I am designing a REST api backend that is meant to be consumed by a javascript front-end.
I am not sure how to communicate server-side business logic errors (e.g. a user trying to retrieve his password with an unknown email, etc.) to the front-end.
After setting a 40x status code on the response, I need to add further detail about the error and I am hesitating between two options:
- Setting custom HTTP headers in the response (e.g.
X-Unknow-Email
) - Setting a JSON in the HTTP response payload with the corresponding error code
Can anyone having already being exposed to designing REST APIs please tell me what the pros and cons are for the two solutions being considered above?