Skip to content

Commit 43aa7db

Browse files
committed
Polish "Provide informative reason when rejecting request with invalid level"
See gh-10588
1 parent 9e5a1b3 commit 43aa7db

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpoint.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ public Object set(@PathVariable String name,
7070
// disabled
7171
return getDisabledResponse();
7272
}
73-
try {
74-
LogLevel logLevel = getLogLevel(configuration);
75-
this.delegate.setLogLevel(name, logLevel);
76-
return ResponseEntity.ok().build();
77-
}
78-
catch (IllegalArgumentException ex) {
79-
throw new InvalidLogLevelException("No such log level " + configuration.get("configuredLevel"));
80-
}
73+
LogLevel logLevel = getLogLevel(configuration);
74+
this.delegate.setLogLevel(name, logLevel);
75+
return ResponseEntity.ok().build();
8176
}
8277

8378
private LogLevel getLogLevel(Map<String, String> configuration) {
8479
String level = configuration.get("configuredLevel");
85-
return (level == null ? null : LogLevel.valueOf(level.toUpperCase()));
80+
try {
81+
return (level == null ? null : LogLevel.valueOf(level.toUpperCase()));
82+
}
83+
catch (IllegalArgumentException ex) {
84+
throw new InvalidLogLevelException(level);
85+
}
8686
}
8787

8888
/**
@@ -92,8 +92,8 @@ private LogLevel getLogLevel(Map<String, String> configuration) {
9292
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "No such log level")
9393
public static class InvalidLogLevelException extends RuntimeException {
9494

95-
public InvalidLogLevelException(String string) {
96-
super(string);
95+
public InvalidLogLevelException(String level) {
96+
super("Log level '" + level + "' is invalid");
9797
}
9898

9999
}

0 commit comments

Comments
 (0)