Skip to content

Commit

Permalink
Merge pull request #10174 from playframework/mergify/bp/2.8.x/pr-10121
Browse files Browse the repository at this point in the history
Allow customization of error message when error handler failed (bp #10121)
  • Loading branch information
mergify[bot] committed Apr 9, 2020
2 parents 16ed15e + cf0849f commit b0e6bac
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/play/src/main/java/play/http/DefaultHttpErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,29 @@ public CompletionStage<Result> onServerError(RequestHeader request, Throwable ex
}
} catch (Exception e) {
logger.error("Error while handling error", e);
return CompletableFuture.completedFuture(Results.internalServerError());
return CompletableFuture.completedFuture(
Results.internalServerError(fatalErrorMessage(request, e)));
}
}

/**
* Invoked when handling a server error with this error handler failed.
*
* <p>As a last resort this method allows you to return a (simple) error message that will be send
* along with a "500 Internal Server Error" response. It's highly recommended to just return a
* simple string, without doing any fancy processing inside the method (like accessing files,...)
* that could throw exceptions. This is your last chance to send a meaningful error message when
* everything else failed.
*
* @param request The request that triggered the server error.
* @param exception The server error.
* @return An error message which will be send as last resort in case handling a server error with
* this error handler failed.
*/
protected String fatalErrorMessage(RequestHeader request, Throwable exception) {
return "";
}

/**
* Responsible for logging server errors.
*
Expand Down

0 comments on commit b0e6bac

Please sign in to comment.