Response status

One of the important things to focus on with REST services is the response status of an error response. The following table shows the scenarios and the error response status to use:

Situation Response Status
The request body does not meet the API specification. It does not contain enough details or contains validation errors. ;400 BAD REQUEST
Authentication or authorization failure. 401 UNAUTHORIZED
The user cannot perform the operation due to various factor, such as exceeding limits. 403 FORBIDDEN
The resource does not exist. 404 NOT FOUND
Unsupported operation, for example, trying POST on a resource where only GET is allowed. ; 405 METHOD NOT ALLOWED
Error on a server. Ideally, this should not happen. The consumer ;would not be able to fix this. ; 500 INTERNAL SERVER ERROR

In this section, we looked at the default exception handling provided by Spring Boot and how we can customize it further to suit our needs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset