http_status_exceptions plugin in ruby on rails
http_status_exceptions is a simple plugin to enable the use of exceptions to generate responses with different HTTP status codes.
This can be used to cleanup your controller in handling edge-cases.
For instance, you could raise a HTTPStatus::Forbidden exception if the user is not authorized to perform restricted action, or you could raise a HTTPStatus::PaymentRequired if the user should renew its membership to your website. By default, this plugin will send an empty response with the desired HTTP status code. It is possible to respond with a customized error page as well. In the case of HTTPStatus::PaymentRequired, a response with a credit card payment form can be used, so that the user easily can renew his membership.
Read more…