raise errors from error
This allows us to test custom errors easier
This commit is contained in:
parent
be5f5270ec
commit
0eca3f46c7
|
@ -738,7 +738,6 @@ module Sinatra
|
||||||
end
|
end
|
||||||
body = returned.to_result(context)
|
body = returned.to_result(context)
|
||||||
rescue => e
|
rescue => e
|
||||||
raise e if options.raise_errors
|
|
||||||
request.env['sinatra.error'] = e
|
request.env['sinatra.error'] = e
|
||||||
context.status(500)
|
context.status(500)
|
||||||
result = (errors[e.class] || errors[ServerError]).invoke(request)
|
result = (errors[e.class] || errors[ServerError]).invoke(request)
|
||||||
|
@ -763,7 +762,10 @@ module Sinatra
|
||||||
|
|
||||||
def setup!
|
def setup!
|
||||||
configure do
|
configure do
|
||||||
error { '<h1>Internal Server Error</h1>'}
|
error do
|
||||||
|
raise request.env['sinatra.error'] if Sinatra.options.raise_errors
|
||||||
|
'<h1>Internal Server Error</h1>'
|
||||||
|
end
|
||||||
not_found { '<h1>Not Found</h1>'}
|
not_found { '<h1>Not Found</h1>'}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,18 @@ context "Custom Errors (in general)" do
|
||||||
|
|
||||||
Sinatra.application.options.raise_errors = true
|
Sinatra.application.options.raise_errors = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class UnmappedError < RuntimeError; end
|
||||||
|
|
||||||
|
specify "should bring unmapped error back to the top" do
|
||||||
|
get '/' do
|
||||||
|
raise UnmappedError, 'test'
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raises(UnmappedError) do
|
||||||
|
get_it '/'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,8 @@ context "Mapped errors" do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
Sinatra.application = nil
|
Sinatra.application = nil
|
||||||
Sinatra.application.options.raise_errors = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
|
||||||
Sinatra.application.options.raise_errors = true
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
specify "are rescued and run in context" do
|
specify "are rescued and run in context" do
|
||||||
|
|
||||||
error FooError do
|
error FooError do
|
||||||
|
|
Loading…
Reference in New Issue