Improve (add) friendly JSON API error messages (at least generic ones)

AI-generated summary

In a discussion titled ‘Improve (add) friendly JSON API error messages (at least generic ones)’, dylanh724 reports that current API error responses (e.g., when POSTing to /posts) return only HTTP status codes without descriptive messages — such as when a secret is mistyped or a required field is missing. Examples include cryptic ‘CSRF’ errors or 500s that offer no user guidance. dylanh724 suggests clearer, standardized JSON-formatted errors like { "error": { "msg": "Invalid API/Secret Combination: Extra info here", "code": "ACCESS_DENIED" } } to improve developer experience. riking adds that the current bad CSRF error is returned as an array instead of an object, highlighting inconsistency. codinghorror requests more specific details about the requests being sent. In reply, dylanh724 clarifies the exact payloads: one with a typo’d secret and another omitting a required field (e.g., unchecking ‘raw’), including screenshots of the requests. The consensus is that current error handling is unhelpful and inconsistent, and a move toward human-readable, structured JSON errors would significantly improve usability and align with standard API practices.

If I POST to /posts and something is wrong, here is what’s returned as an error:

image

only the code shows - no message (not friendly). This is the error when I typo the secret.

Here’s another form of error, leaving out a field:

image

bad “CSRF” – No one knows what the heck does that means. You can see 403 forbidden and get the hint for the code, but let’s say it wasn’t a forbidden one: It goes back to the 500 error.

These errors… really suck haha. Suggestions:

Invalid Parameters: Missing xx field(s)

Forbidden: Invalid secret/key combo

Something like these. Since error messages are so common, I actually thought I was glitched out since I only had a code returned, so even something generic would be better than nothing.

It would also be more intuitive if the errors were in json for consideration of future additions, and to be more intuitive to handling error standards of most other API’s.

{
  "error": {
    "msg": "Invalid API/Secret Combination: Extra info here",
    "code": "ACCESS_DENIED"
  {
}

Thoughts?

It’s also pretty great how the bad csrf error is an array instead of an object.

1 „Gefällt mir“

You need more specific reports of exactly what you are sending.

1 „Gefällt mir“

Yea it’s pretty awkward and inconsistent right now.

In OP, I mentioned I posted to /posts – the first one I typo’d the secret. The 2nd one I left out a required field. To be specific as to exactly what I wrote:

1st post (typo key):

2nd post (uncheck “raw”, leaving out a required field):

1 „Gefällt mir“