i can has error map?
This commit is contained in:
parent
776d39aa0d
commit
ba2d234cce
|
@ -360,13 +360,14 @@ module Sinatra
|
|||
rescue => e
|
||||
raise e if options.raise_errors
|
||||
env['sinatra.error'] = e
|
||||
result = (errors[500] || basic_error).invoke(env)
|
||||
context.status(500)
|
||||
result = (errors[e.class] || errors[500] || basic_error).invoke(env)
|
||||
returned = catch(:halt) do
|
||||
[:complete, context.instance_eval(&result.block)]
|
||||
end
|
||||
body = returned.to_result(context)
|
||||
context.status(500)
|
||||
context.body = String === body ? [*body] : body
|
||||
body = '' unless body.respond_to?(:each)
|
||||
context.body = body.kind_of?(String) ? [*body] : body
|
||||
context.finish
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
require File.dirname(__FILE__) + '/helper'
|
||||
|
||||
class FooError < RuntimeError; end
|
||||
|
||||
context "Mapped errors" do
|
||||
|
||||
before(:each) do
|
||||
Sinatra.application = nil
|
||||
Sinatra.application.options.raise_errors = false
|
||||
end
|
||||
|
||||
|
||||
specify "are rescued and run in context" do
|
||||
|
||||
error FooError do
|
||||
'MAPPED ERROR!'
|
||||
end
|
||||
|
||||
get '/' do
|
||||
raise FooError.new
|
||||
end
|
||||
|
||||
get_it '/'
|
||||
|
||||
should.be.server_error
|
||||
body.should.equal 'MAPPED ERROR!'
|
||||
|
||||
end
|
||||
|
||||
specify "renders empty if no each method on result" do
|
||||
|
||||
error FooError do
|
||||
nil
|
||||
end
|
||||
|
||||
get '/' do
|
||||
raise FooError.new
|
||||
end
|
||||
|
||||
get_it '/'
|
||||
|
||||
should.be.server_error
|
||||
body.should.be.empty
|
||||
|
||||
end
|
||||
|
||||
specify "doesn't override status if set" do
|
||||
|
||||
error FooError do
|
||||
status(200)
|
||||
end
|
||||
|
||||
get '/' do
|
||||
raise FooError.new
|
||||
end
|
||||
|
||||
get_it '/'
|
||||
|
||||
should.be.ok
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue