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


(Dylan Hunt) #1

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

image

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?


Discourse always posts in general using API
(Kane York) #2

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


(Jeff Atwood) #3

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


(Dylan Hunt) #4

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):