Skip to content

Commit

Permalink
Return JsonError from endpoint; fix tests to match
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Moss committed Jul 23, 2018
1 parent f795065 commit c2589fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.QueryValue;
import io.micronaut.http.hateos.JsonError;
import io.micronaut.management.endpoint.Endpoint;
import io.micronaut.management.endpoint.EndpointConfiguration;
import io.micronaut.management.endpoint.Read;
Expand Down Expand Up @@ -101,7 +102,9 @@ public HttpResponse setLogLevel(@QueryValue @NotBlank String name,
configuredLevel != null ? configuredLevel : LogLevel.NOT_SPECIFIED);
return HttpResponse.ok();
} catch (IllegalArgumentException ex) {
return HttpResponse.badRequest(ex.getMessage());
JsonError error = new JsonError(ex.getMessage());
return HttpResponse.badRequest(error);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class LoggersEndpointSpec extends Specification {

and:
e.response.status == HttpStatus.BAD_REQUEST
e.message.contains 'Cannot deserialize value of type `io.micronaut.management.endpoint.loggers.LogLevel` from String "FOO"'
}

void 'test that an attempt to set ROOT logger to NOT_SPECIFIED level will fail'() {
Expand All @@ -195,6 +196,7 @@ class LoggersEndpointSpec extends Specification {

and:
e.response.status == HttpStatus.BAD_REQUEST
e.message == 'The level of the root logger cannot be set to null'
}

}

0 comments on commit c2589fa

Please sign in to comment.