Skip to content

Commit

Permalink
#28325 doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizzio-dotCMS committed Apr 30, 2024
1 parent 4ae0158 commit 543afcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,12 @@ private String getMessage(final Exception originalException, final Exception han
+ " Occurred With no error message provided.";
}


/**
* On recent versions of RESTEasy, the custom message is stored in the reasonPhrase
* The WebApplicationException message is immutable and can't be changed 404 is always "Not Found"
* @param ex The exception that was thrown
* @return The message to display
*/
String getWebApplicationExceptionMessage(final WebApplicationException ex) {
final Response response = ex.getResponse();
if (response instanceof BuiltResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ void Test_Handle_WebApplication_Exception() {
NotFoundException noise = new NotFoundException("No pineapple Flavor today");
Exception handled = exceptionHandler.handle(noise);
Assertions.assertTrue(handled instanceof WebApplicationException);
// On recent versions of Quarkus, the custom message is set as the reason phrase of the response
//WebApplications have an immutable message so we can't change it. 404 will always be Not Found etc...
BuiltResponse response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
//Therefore the custom message needs to be extracted from the response
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(404)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(404)));

Expand All @@ -55,35 +58,30 @@ void Test_Handle_WebApplication_Exception() {
Assertions.assertTrue(handled instanceof WebApplicationException);
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(400)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(400)));

ForbiddenException forbiddenException = new ForbiddenException("LOL");
handled = exceptionHandler.handle(forbiddenException);
Assertions.assertTrue(handled instanceof WebApplicationException);
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(403)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(403)));

WebApplicationException unauthorized = new WebApplicationException(401);
handled = exceptionHandler.handle(unauthorized);
Assertions.assertTrue(handled instanceof WebApplicationException);
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(401)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(401)));

WebApplicationException internalServerError = new WebApplicationException(500);
handled = exceptionHandler.handle(internalServerError);
Assertions.assertTrue(handled instanceof WebApplicationException);
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(500)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(500)));

NotAllowedException moreNoise = new NotAllowedException("Not Allowed");
handled = exceptionHandler.handle(moreNoise);
Assertions.assertTrue(handled instanceof WebApplicationException);
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.fallback()));
//Assertions.assertTrue(handled.getMessage().contains(config.fallback()));

}

Expand Down

0 comments on commit 543afcb

Please sign in to comment.