diff --git a/src/main/java/org/kiwiproject/jaxrs/KiwiStandardResponses.java b/src/main/java/org/kiwiproject/jaxrs/KiwiStandardResponses.java index 7131beea..fa8447f0 100644 --- a/src/main/java/org/kiwiproject/jaxrs/KiwiStandardResponses.java +++ b/src/main/java/org/kiwiproject/jaxrs/KiwiStandardResponses.java @@ -319,6 +319,28 @@ public static Response.ResponseBuilder standardNotFoundResponseBuilder(String er return standardErrorResponseBuilder(Response.Status.NOT_FOUND, errorDetails); } + /** + * Returns a 500 Internal Server Error response containing an {@link ErrorMessage} entity which uses + * {@code errorDetails} as the detailed error message. + * + * @param errorDetails the error message to use + * @return a 500 Internal Server Error response with {@code application/json} content type + */ + public static Response standardInternalServerErrorResponse(String errorDetails) { + return standardInternalServerErrorResponseBuilder(errorDetails).build(); + } + + /** + * Returns a response builder with 500 Internal Server Error status and an {@link ErrorMessage} entity + * which uses {@code errorDetails} as the detailed error message. + * + * @param errorDetails the error message to use + * @return a response builder with the given status code and {@code application/json} content type + */ + public static Response.ResponseBuilder standardInternalServerErrorResponseBuilder(String errorDetails) { + return standardErrorResponseBuilder(Response.Status.INTERNAL_SERVER_ERROR, errorDetails); + } + /** * Returns a response having the given status and an {@link ErrorMessage} entity which uses {@code errorDetails} * as the detailed error message. diff --git a/src/test/java/org/kiwiproject/jaxrs/KiwiStandardResponsesTest.java b/src/test/java/org/kiwiproject/jaxrs/KiwiStandardResponsesTest.java index 7f66b110..a451b466 100644 --- a/src/test/java/org/kiwiproject/jaxrs/KiwiStandardResponsesTest.java +++ b/src/test/java/org/kiwiproject/jaxrs/KiwiStandardResponsesTest.java @@ -271,6 +271,27 @@ void shouldReturnNotFoundResponse_WithErrorMessageEntity() { } } + @Nested + class StandardInternalServerErrorResponse { + + @Test + void shouldReturnResponse_With500StatusAndErrorMessageEntity() { + var response = KiwiStandardResponses.standardInternalServerErrorResponse("This is the error message. It is very helpful."); + + assertResponseEntityHasOneErrorMessage(response, 500, "This is the error message. It is very helpful."); + assertJsonResponseType(response); + } + + @Test + void shouldReturnResponseBuilder_With500StatusAndErrorMessageEntity() { + var builder = KiwiStandardResponses.standardInternalServerErrorResponseBuilder("This is the error message. It is very helpful."); + var response = builder.build(); + + assertResponseEntityHasOneErrorMessage(response, 500, "This is the error message. It is very helpful."); + assertJsonResponseType(response); + } + } + @Nested class StandardErrorResponse {