Class ProblemJsonExceptionHandler
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
com.irurueta.authserver.authorization.api.web.ProblemJsonExceptionHandler
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.MessageSourceAware
- Direct Known Subclasses:
AccountExceptionHandler,ClientExceptionHandler,MfaExceptionHandler,OttExceptionHandler,PasskeyExceptionHandler,SignInMethodExceptionHandler
public class ProblemJsonExceptionHandler
extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
Base of the exception handlers of the REST API: every problem detail is answered as
application/problem+json (RFC 9457), as the contracts under apis/ declare.
The interfaces generated from a contract map each operation with the media types it produces, for example
application/json and application/problem+json. Spring MVC keeps those as the producible types of
an error answer too and, for a client that accepts anything, would pick the first one: a problem detail would then
go out as application/json. Setting the content type of every problem answer keeps the contract's media
type whatever the order of the generated list.
It is not an advice itself: each feature declares its own @RestControllerAdvice extending it, scoped to its
controller.
-
Field Summary
Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.http.ResponseEntity<Object> createResponseEntity(@Nullable Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatusCode statusCode, org.springframework.web.context.request.WebRequest request) Sets the problem media type on the answers built by the parent class, such as request validation failures.protected static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> problemResponse(org.springframework.http.ProblemDetail problem) Answers a problem detail with its own status, asapplication/problem+json.protected static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> problemResponse(org.springframework.http.ProblemDetail problem, org.springframework.http.HttpHeaders headers) Answers a problem detail with its own status and the given headers, asapplication/problem+json.Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
createProblemDetail, getMessageSource, handleAsyncRequestNotUsableException, handleAsyncRequestTimeoutException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHandlerMethodValidationException, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMaxUploadSizeExceededException, handleMethodArgumentNotValid, handleMethodValidationException, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleNoResourceFoundException, handleServletRequestBindingException, handleTypeMismatch, setMessageSource
-
Constructor Details
-
ProblemJsonExceptionHandler
public ProblemJsonExceptionHandler()
-
-
Method Details
-
problemResponse
protected static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> problemResponse(org.springframework.http.ProblemDetail problem) Answers a problem detail with its own status, asapplication/problem+json.- Parameters:
problem- the problem.- Returns:
- the response carrying the problem.
-
problemResponse
protected static org.springframework.http.ResponseEntity<org.springframework.http.ProblemDetail> problemResponse(org.springframework.http.ProblemDetail problem, org.springframework.http.HttpHeaders headers) Answers a problem detail with its own status and the given headers, asapplication/problem+json.- Parameters:
problem- the problem.headers- headers of the answer, such asRetry-After.- Returns:
- the response carrying the problem.
-
createResponseEntity
protected org.springframework.http.ResponseEntity<Object> createResponseEntity(@Nullable Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatusCode statusCode, org.springframework.web.context.request.WebRequest request) Sets the problem media type on the answers built by the parent class, such as request validation failures.- Overrides:
createResponseEntityin classorg.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler- Parameters:
body- body of the answer, normally a problem detail.headers- headers of the answer.statusCode- status of the answer.request- the current request.- Returns:
- the answer.
-