class Sinatra::Base
def error_detection
def error_detection errmap = self.class.errors yield rescue NotFound => boom @env['sinatra.error'] = boom @response.status = 404 @response.body = ['<h1>Not Found</h1>'] handler = errmap[boom.class] || errmap[NotFound] invoke handler unless handler.nil? rescue ::Exception => boom @env['sinatra.error'] = boom if options.dump_errors? msg = ["#{boom.class} - #{boom.message}:", *boom.backtrace].join("\n ") @env['rack.errors'] << msg end raise boom if options.raise_errors? @response.status = 500 invoke errmap[boom.class] || errmap[Exception] ensure if @response.status >= 400 && errmap.key?(response.status) invoke errmap[response.status] end end