3.3.5.REST API Error Handling Practices

  • 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

          {
            status: {}
            payload: {}
          }

Last updated

Was this helpful?