Error Handling
We want to follow the common best-practice of raising a specific error class:
The problem is, this error would cause our server to return a 500
status code, without much helpful detail. Instead, we want to
customize our responses based on the error thrown.
Enter jsonapi_errorable, which provides a simple DSL to do just that:
Here we’ve customized the error response to send the HTTP status code 403
(forbidden) whenever this particular exception class is raised.
Maybe our error class already has a message we want to display to the user:
For full documentation on everything you can do here, head over to the jsonapi_errorable documentation.