Commit 43aa7dba authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Provide informative reason when rejecting request with invalid level"

See gh-10588
parent 9e5a1b32
...@@ -70,19 +70,19 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter { ...@@ -70,19 +70,19 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter {
// disabled // disabled
return getDisabledResponse(); return getDisabledResponse();
} }
try { LogLevel logLevel = getLogLevel(configuration);
LogLevel logLevel = getLogLevel(configuration); this.delegate.setLogLevel(name, logLevel);
this.delegate.setLogLevel(name, logLevel); return ResponseEntity.ok().build();
return ResponseEntity.ok().build();
}
catch (IllegalArgumentException ex) {
throw new InvalidLogLevelException("No such log level " + configuration.get("configuredLevel"));
}
} }
private LogLevel getLogLevel(Map<String, String> configuration) { private LogLevel getLogLevel(Map<String, String> configuration) {
String level = configuration.get("configuredLevel"); String level = configuration.get("configuredLevel");
return (level == null ? null : LogLevel.valueOf(level.toUpperCase())); try {
return (level == null ? null : LogLevel.valueOf(level.toUpperCase()));
}
catch (IllegalArgumentException ex) {
throw new InvalidLogLevelException(level);
}
} }
/** /**
...@@ -92,8 +92,8 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter { ...@@ -92,8 +92,8 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter {
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "No such log level") @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "No such log level")
public static class InvalidLogLevelException extends RuntimeException { public static class InvalidLogLevelException extends RuntimeException {
public InvalidLogLevelException(String string) { public InvalidLogLevelException(String level) {
super(string); super("Log level '" + level + "' is invalid");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment