3.3.5.REST API Error Handling Practices
Previous3.3.4.Walkthrough: Creating a Vacations API in Node JSNext3.3.6.Walkthrough: Implementation of error handling for POST API
Last updated
Last updated
API response
HTTP status codes
over 70 status code
Decide the code that you will use for your API
Restrict the number of HTTP codes to a maximum of 8
Must use 200/ 400/ 500
Error response
1.Set the HTTP status codes to 4xx or 5xx
2.Set the Content-Type of error response; common to use json
Content-Type: "application/json"
3.Use numeric error codes for application specific errors
e.g., error = 7002
4.Use a standard error template for error response body
Alternative approach to error response
Always send back HTTP status = 200 OOK
Response