Package io.micronaut.problem
Class ProblemJsonErrorResponseBodyProvider
java.lang.Object
io.micronaut.problem.ProblemJsonErrorResponseBodyProvider
- All Implemented Interfaces:
io.micronaut.http.server.exceptions.response.ErrorResponseBodyProvider<org.zalando.problem.Problem>,io.micronaut.http.server.exceptions.response.JsonErrorResponseBodyProvider<org.zalando.problem.Problem>
@Singleton
public class ProblemJsonErrorResponseBodyProvider
extends Object
implements io.micronaut.http.server.exceptions.response.JsonErrorResponseBodyProvider<org.zalando.problem.Problem>
JsonErrorResponseBodyProvider to respond Problem responses.
- Adds application/problem+json content type
- If the cause is a
ThrowableProblem, it returns as the body. - If the cause is not a
ThrowableProblem, it generates a default Problem based on theErrorContextand returns it as the HTTP Body.
- Since:
- 1.0
- Author:
- Sergio del Amo
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor. -
Method Summary
Modifier and TypeMethodDescription@NonNull org.zalando.problem.Problembody(@NonNull io.micronaut.http.server.exceptions.response.ErrorContext errorContext, @NonNull io.micronaut.http.HttpResponse<?> response) protected @NonNull org.zalando.problem.ThrowableProblemdefaultProblem(@NonNull io.micronaut.http.server.exceptions.response.ErrorContext errorContext, @NonNull io.micronaut.http.HttpStatus httpStatus) Creates aThrowableProblemwhen the root cause was not an exception of typeThrowableProblem.protected booleanincludeErrorMessage(@NonNull io.micronaut.http.server.exceptions.response.ErrorContext errorContext) WhetherThrowableProblem, created when the root cause is not an exception of typeThrowableProblem, should contain Error::getMessage in the problem detail.
-
Field Details
-
APPLICATION_PROBLEM_JSON
- See Also:
-
-
Constructor Details
-
ProblemJsonErrorResponseBodyProvider
Constructor.- Parameters:
config- Problem configuration
-
-
Method Details
-
contentType
- Specified by:
contentTypein interfaceio.micronaut.http.server.exceptions.response.ErrorResponseBodyProvider<org.zalando.problem.Problem>- Specified by:
contentTypein interfaceio.micronaut.http.server.exceptions.response.JsonErrorResponseBodyProvider<org.zalando.problem.Problem>
-
body
@NonNull public @NonNull org.zalando.problem.Problem body(@NonNull @NonNull io.micronaut.http.server.exceptions.response.ErrorContext errorContext, @NonNull @NonNull io.micronaut.http.HttpResponse<?> response) - Specified by:
bodyin interfaceio.micronaut.http.server.exceptions.response.ErrorResponseBodyProvider<org.zalando.problem.Problem>
-
defaultProblem
@NonNull protected @NonNull org.zalando.problem.ThrowableProblem defaultProblem(@NonNull @NonNull io.micronaut.http.server.exceptions.response.ErrorContext errorContext, @NonNull @NonNull io.micronaut.http.HttpStatus httpStatus) Creates aThrowableProblemwhen the root cause was not an exception of typeThrowableProblem.- Parameters:
errorContext- Error ContexthttpStatus- HTTP Status- Returns:
- Default problem
-
includeErrorMessage
protected boolean includeErrorMessage(@NonNull @NonNull io.micronaut.http.server.exceptions.response.ErrorContext errorContext) WhetherThrowableProblem, created when the root cause is not an exception of typeThrowableProblem, should contain Error::getMessage in the problem detail. To avoid accidental information leakage defaults to false unless the root cause is of typeUnsatisfiedRouteExceptionwhich contains helpful information to diagnose the issue (e.g. missing required query value) in the details.- Parameters:
errorContext- Error Context- Returns:
- To avoid accidental information leakage defaults to false unless the root cause is of type
UnsatisfiedRouteException
-