mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
raise errors from error
This allows us to test custom errors easier
This commit is contained in:
parent
be5f5270ec
commit
0eca3f46c7
3 changed files with 16 additions and 8 deletions
|
@ -738,7 +738,6 @@ module Sinatra
|
|||
end
|
||||
body = returned.to_result(context)
|
||||
rescue => e
|
||||
raise e if options.raise_errors
|
||||
request.env['sinatra.error'] = e
|
||||
context.status(500)
|
||||
result = (errors[e.class] || errors[ServerError]).invoke(request)
|
||||
|
@ -763,7 +762,10 @@ module Sinatra
|
|||
|
||||
def setup!
|
||||
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>'}
|
||||
end
|
||||
|
||||
|
|
|
@ -46,6 +46,18 @@ context "Custom Errors (in general)" do
|
|||
|
||||
Sinatra.application.options.raise_errors = true
|
||||
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
|
||||
|
||||
|
|
|
@ -6,14 +6,8 @@ context "Mapped errors" do
|
|||
|
||||
setup do
|
||||
Sinatra.application = nil
|
||||
Sinatra.application.options.raise_errors = false
|
||||
end
|
||||
|
||||
teardown do
|
||||
Sinatra.application.options.raise_errors = true
|
||||
end
|
||||
|
||||
|
||||
specify "are rescued and run in context" do
|
||||
|
||||
error FooError do
|
||||
|
|
Loading…
Reference in a new issue