From the course: Java EE: RESTful Service with JAX-RS 2.0

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Manage validation failures

Manage validation failures

From the course: Java EE: RESTful Service with JAX-RS 2.0

Start my 1-month free trial

Manage validation failures

- [Instructor] We have seen that when Bean Validation fails the client will receive a 400 bad request response from the server. Now you will learn how to respond to the client with a far more informative response. We will discuss two ways to present the client with a response that identifies the data that has caused the data integrity violation. One technique is to respond to the client with a list of fields that cause the problem in a custom key value pair HTTP header. And the other way is to use the response's body to encapsulate the error response. Both techniques have their pros and cons. And the one you choose largely depends on what suits your business model and client's requirements. In either case, it is essential that you sufficiently document it so that the front-end developer knows how to use the error response. Let's look at the first technique. Here I am going to suggest one way to handle the response in the response body. As there is no accepted convention, you are free…

Contents