Consider a Person
entity with a property name
that is annotated as @NotNull
. Then a simple PersonRepository
and this repo exposed with Spring Data Rest.
When I POST
to create a new Person
, if the name
property is null
a ValidationException
occurs as expected. But what I actually get on the client is an Internal Server Error (500) and the message is a TransactionSystemException
that happened much later in the exception chain.
What I'd expect to get is a Bad Request (400) with the actual ValidationException
and all it's useful information so the client can know what's wrong with the posted data.
There seems to be a way to attach custom validators with SDR as explained here . But the thing is, this is not a custom validator, it's a standard bean validation that happens when the repository is asked to save data. So I'm not really sure how those two come together.
So questions:
Thanks a lot.
What you need is a proper ExceptionHandler
, it will handle back end exceptions and send meaningful rich messages (json/xml) to the front end client.
Take a look a this git repository
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.