-
Notifications
You must be signed in to change notification settings - Fork 9
Errors Handling
This page is up to date for Rango 0.1.
There is a lot of ways how you can handle exceptions in MVC pattern. In Merb you have special Exceptions
controller, Rails prefer to keep it in one controller, or you can require more complex setup … so Rango just let you set it up easily.
All classes derivated from Rango::HttpError
can be converted into Rack response (see Rango::HttpError#to_response
).
- Exceptions classes in Rango
- List of HTTP Status Codes
- rescue_http_error(exception)
should returns standard rack array with [status, headers, body]
- render_http_error(exception)
should returns just a string which will be returned as the response body.
- if you need to customize something, use exception.content_type = "text/html"
and exception.headers[foo] = bar
Well, not exactly the same syntax, but definitely the same concept:
This solution will automatically render errors/not_found
if you raise NotFound
error, errors/internal_server_error
if you raise InternalServerError
error etc.
As you know, in Rango you aren’t limited on controllers or whatever. Lets take a look how you can implement default exceptions handling from controllers for you custom application:
And here we are! Or, in similar way as above, you can use render "errors/#{exception.to_snakecase}"
or whatever you want.
The original prototype
exc = Error302.new(“http://example.com”)
exc.headers[“foo”] = bar
raise exc
raise MovedPermanently, “http://example.com” # this is how the Rango::Controller#redirect method works