Exceptions are automatically caught when in production mode, but not in development. In production, for our example, the application returns a (Internal Server Error); in development, we’ll see the stack trace and all the information to debug the code.
This behavior can be changed with the handle_exceptions
setting in apps/web/application.rb
.
accepts a Hash where the key is the exception to handle, and the value is the corresponding HTTP status code. In our example, when ArgumentError
is raised, it will be handled as a 400
(Bad Request).
If the mapping with a custom HTTP status doesn’t fit our needs, we can specify a custom handler and manage the exception by ourselves.
When a exception is raised it will be handled by :handle_permission_error
. It MUST accept an exception
argument—the exception instance raised inside #call
.
When specifying a custom exception handler, it MUST accept an argument.