Two-part Rails question:
Part 1
When a Rails controller raises an unhandled exception, an HTTP 500 (Internal Server Error) status code is typically returned in the response to the caller.
However, I've observed that certain specific types of exceptions cause a different HTTP status code to be returned. For example, an unhandled ActiveRecord::RecordNotFound exception (as from a find_by! call that failed to find a matching record) causes an HTTP 404 Not Found, rather than an HTTP 500, to be returned.
Short of actually trying it, how can I know which HTTP status code Rails controllers will return for a particular class of unhandled exception?
Part 2
If I want to customize which HTTP status code controllers return for a particular class of exception -- say, a custom derived class of StandardError defined in my application -- how can that be done?