Simple protocol is simple:
- Never intentionally throw exceptions.
- Return a valid JSON object like this for a success:
{
success: true,
payload: {
// the result of the operation, i.e. an http response body
}
}
- Return a valid JSON object like this for an error:
{
success: false,
error: {
// error details or object
}
}
That's it! Both success and error cases are handled the same way and can follow the same code path.