Skip to content

nazeem-soeltan/problem-spring-web-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

problem-spring-web-example

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.

Features

  • ApiException to have fine-grained control on which HTTP status, title and optional error code to use for a Problem.
  • ApiErrorAdviceTrait transforms an ApiException to a Problem.
  • DefaultThrowableAdviceTrait transforms an Exception to a Problem.
  • ApiErrorHandler to delegate ApiException to ApiErrorAdviceTrait, otherwise DefaultThrowableAdviceTrait.
  • CustomBindAdviceTrait, CustomConstraintViolationAdviceTrait and CustomMethodArgumentNotValidAdviceTrait to allow violations to be omitted.
  • TraceableConstraintViolationProblem to provide a trace ID parameter on a ConstraintViolationProblem.
  • TraceableProblemCreator to create a Problem with the trace ID parameter, as it is not possible to add this in a generic way.

Usage

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
}'

About

Example implementation of the Problem Spring Web library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages