Consistently return JSON for API responses
I’ve noticed that the Gainsight API returns JSON responses for 500 errors, but for 400, 402, and 404, it returns plain text.
For example: 500 (Unexpected Error) returns:
{
"message": "Internal Server Error"
}But a 404 (Not Found) error might return something like:
The requested URL /user/email/abc%xyz.com was not found.
Is there a particular reason why a 404 message couldn’t return:
{
"message": "The requested URL /user/email/abc%xyz.com was not found."
}
In short: it would be way easier to handle API responses if they were consistent in their format and structure.
- Everything should be JSON.
- All errors should have a “message” key
- All successful responses should have a ‘response” key
...or something similar.