Best practices to define custom error codes for an API [closed]
Asked Answered
H

1

5

We are planning to develop an API. There are so many cases that a request can be considered as a bad request. For this, We have planned to send a JSON object with error code, error, and additional info

I have put the sample case here when a user sends an illumination image. We considered as this request is bad request and send the following JSON

{
"ErrorCode": 10000,
"Error": "Detected uneven illumination image",
"Additional Info": "Prefer to change the image location"
}

  1. Is our JSON object format is good or we need to add the HTTP Error code like 400/404
  2. How to select this custom error code? We are planning to take the error code number from 10000.

Can someone please help us or provide some trustful resources?

Hurryscurry answered 5/10, 2020 at 7:56 Comment(2)
Why from 10000?Stannum
Randomly we took thisHurryscurry
S
6

Check Stripe API they also use error codes (code) to explain different 4xx errors

Supersensible answered 5/10, 2020 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.