Sinatra::NotFound
exception is raised, or the response’s
status code is 404, the not_found
handler is invoked:
not_found do 'This is nowhere to be found.' end
error
handler is invoked any time an exception is raised from
a route block or a filter.
The exception object can be obtained
from the sinatra.error
Rack variable:
error do 'Sorry there was a nasty error - ' + env['sinatra.error'].name endCustom errors:
error MyCustomError do 'So what happened was...' + env['sinatra.error'].message endThen, if this happens:
get '/' do raise MyCustomError, 'something bad' endYou get this:
So what happened was... something badAlternatively, you can install an error handler for a status code:
error 403 do 'Access forbidden' end get '/secret' do 403 endOr a range:
error 400..510 do 'Boom' endSinatra installs special
not_found
and error
handlers
when running under the development environment to display nice stack
traces and additional debugging information in your browser (esto es,
en producción estos handlers son mucho mas "parcos").