Skip to content

Commit

Permalink
Change the default format of responses returned by QuarkusErrorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Sep 21, 2021
1 parent 02b30c8 commit e49ae01
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void testAcceptUnsupported() {
.get("/unhandled-exception")
.then()
.statusCode(500)
.contentType(TEXT_HTML) // Default to HTML
.body(htmlBodyMatcher());
.contentType(APPLICATION_JSON) // Default to JSON
.body(jsonBodyMatcher());
}

@Test
Expand Down Expand Up @@ -179,8 +179,11 @@ public void testMultipleAcceptHeaders() {
.get("/unhandled-exception")
.then()
.statusCode(500)
.contentType(TEXT_HTML)
.body(htmlBodyMatcher());
// Ideally we'd like TEXT_HTML here, but due to some strange behavior of
// io.vertx.ext.web.ParsedHeaderValues.findBestUserAcceptedIn,
// we get this.
.contentType(APPLICATION_JSON)
.body(jsonBodyMatcher());

given()
.config(multipleAcceptHeadersConfig)
Expand All @@ -190,11 +193,8 @@ public void testMultipleAcceptHeaders() {
.get("/unhandled-exception")
.then()
.statusCode(500)
// Ideally we'd like APPLICATION_JSON here, but due to some strange behavior of
// io.vertx.ext.web.ParsedHeaderValues.findBestUserAcceptedIn,
// we get this.
.contentType(TEXT_HTML)
.body(htmlBodyMatcher());
.contentType(APPLICATION_JSON)
.body(jsonBodyMatcher());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ public void accept(Throwable throwable) {
jsonResponse(event, responseContentType, details, stack);
break;
default:
// We default to HTML representation
switch (contentTypeDefault.orElse(HttpConfiguration.PayloadHint.HTML)) {
case JSON:
jsonResponse(event, ContentTypes.APPLICATION_JSON, details, stack);
break;
// We default to JSON representation
switch (contentTypeDefault.orElse(HttpConfiguration.PayloadHint.JSON)) {
case HTML:
htmlResponse(event, details, exception);
break;
case JSON:
default:
jsonResponse(event, ContentTypes.APPLICATION_JSON, details, stack);
break;
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testRestEndPointReturnValueValidation() {
.then()
.body(containsString(ResteasyReactiveViolationException.class.getName())) // Exception type
.body(containsString("numeric value out of bounds")) // Exception message
.body(containsString("testRestEndPointReturnValueValidation.<return value>"))
.body(containsString("testRestEndPointReturnValueValidation.<return value>"))
.body(containsString(HibernateValidatorTestResource.class.getName())) // Stack trace
.statusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testCDIBeanMethodValidationUncaught() {
ValidatableResponse response = RestAssured.when()
.get("/hibernate-validator/test/cdi-bean-method-validation-uncaught")
.then()
.body(containsString("Internal Server Error"))
.body(containsString("Error id"))
.statusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
if (isInternalErrorExceptionLeakedInQuarkusErrorHandlerResponse()) {
response
Expand Down Expand Up @@ -182,13 +182,13 @@ public void testRestEndPointReturnValueValidation() {
ValidatableResponse response = RestAssured.when()
.get("/hibernate-validator/test/rest-end-point-return-value-validation/plop/")
.then()
.body(containsString("Internal Server Error"))
.body(containsString("Error id"))
.statusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
if (isInternalErrorExceptionLeakedInQuarkusErrorHandlerResponse()) {
response
.body(containsString(ResteasyViolationExceptionImpl.class.getName())) // Exception type
.body(containsString("numeric value out of bounds")) // Exception message
.body(containsString("testRestEndPointReturnValueValidation.&lt;return value&gt;"))
.body(containsString("testRestEndPointReturnValueValidation.<return value>"))
.body(containsString(HibernateValidatorTestResource.class.getName())); // Stack trace
}

Expand Down

0 comments on commit e49ae01

Please sign in to comment.