Provides an example implementation of the Problem Spring Web
Problem Spring Web is a library that provides an implementation of RFC4708: Problem Details for HTTP APIs.
ApiException
to have fine-grained control on which HTTP status, title and optional error code to use for a Problem.ApiErrorAdviceTrait
transforms anApiException
to a Problem.DefaultThrowableAdviceTrait
transforms an Exception to a Problem.ApiErrorHandler
to delegateApiException
toApiErrorAdviceTrait
, otherwiseDefaultThrowableAdviceTrait
.CustomBindAdviceTrait
,CustomConstraintViolationAdviceTrait
andCustomMethodArgumentNotValidAdviceTrait
to allow violations to be omitted.TraceableConstraintViolationProblem
to provide a trace ID parameter on aConstraintViolationProblem
.TraceableProblemCreator
to create a Problem with the trace ID parameter, as it is not possible to add this in a generic way.
Clone this repository
git clone git@github.com:nazeem-soeltan/problem-spring-web-example.git
Run the application. In the root directory of the repository
./mvnw spring-boot:run
Get exception keys list
curl --request GET \
--url http://localhost:8080/api/exception-keys \
--header 'X-Consumer-Authorities: ROLE_DEVELOPER' \
--header 'X-Consumer-Username: nazeem'
Use key to throw exception
curl --request GET \
--url http://localhost:8080/api/exception-keys/access-denied \
--header 'X-Consumer-Authorities: ROLE_DEVELOPER' \
--header 'X-Consumer-Username: nazeem'
Also possible to throw customizable exceptions
curl --request POST \
--url http://localhost:8080/api/exception-keys/ \
--header 'Content-Type: application/json' \
--header 'X-Consumer-Authorities: ROLE_DEVELOPER' \
--header 'X-Consumer-Username: nazeem' \
--data '{
"key": "any-key",
"status": 401
}'