vpmalley / jetlag

Bases of a future travel blog platform
MIT License
1 stars 0 forks source link

API calls should always return JSON in case of errors #63

Closed Vallenain closed 7 years ago

Vallenain commented 7 years ago

The calls to /api/0.1/ return HTML document in case of error (I think it's the default behaviour of Laravel). But for APIs, those responses should be programmatically read and so we'd need a standard JSON error object. Probably something like

{
  error_code: 'AN_ERROR_IDENTIFIER',
  error_message: 'some human readable message, for the developper mostly'
}
vpmalley commented 7 years ago

and a good way to resolve this is in the answers of this question: http://stackoverflow.com/questions/28444556/laravel-5-general-error-as-json

vpmalley commented 7 years ago

fixed, the chosen format is:

{ "error": { "status" : <number>, "message" : <string> } }

where the status is a HTTP status code. It can be returned by writing anywhere abort(status, message); in the PHP code.