From e49ae0109369b099836b10093ba3b6e21f97a9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 20 Sep 2021 14:43:57 +0200 Subject: [PATCH] Change the default format of responses returned by QuarkusErrorHandler --- .../vertx/http/UnhandledExceptionTest.java | 18 +++++++++--------- .../http/runtime/QuarkusErrorHandler.java | 11 ++++++----- .../HibernateValidatorFunctionalityTest.java | 2 +- .../HibernateValidatorFunctionalityTest.java | 6 +++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/UnhandledExceptionTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/UnhandledExceptionTest.java index 4a43f13493124..623efb2fed0f5 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/UnhandledExceptionTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/UnhandledExceptionTest.java @@ -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 @@ -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) @@ -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 diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java index bb7b76d586dc2..b469d594b17ed 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java @@ -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; } diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java index b7480e36695cb..8ef836dcb6ded 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java @@ -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.")) .body(containsString(HibernateValidatorTestResource.class.getName())) // Stack trace .statusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); diff --git a/integration-tests/hibernate-validator/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java b/integration-tests/hibernate-validator/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java index d6def9b5d81be..a5cde57c4284b 100644 --- a/integration-tests/hibernate-validator/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java +++ b/integration-tests/hibernate-validator/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java @@ -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 @@ -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.<return value>")) + .body(containsString("testRestEndPointReturnValueValidation.")) .body(containsString(HibernateValidatorTestResource.class.getName())); // Stack trace }