1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Fix issue with custom error handler on bad request

This commit is contained in:
Jordan Owens 2017-10-03 16:50:02 -04:00
parent 89cbd96866
commit b7163b2282
2 changed files with 17 additions and 1 deletions

View file

@ -915,6 +915,7 @@ module Sinatra
def call!(env) # :nodoc:
@env = env
@params = IndifferentHash.new
@request = Request.new(env)
@response = Response.new
template_cache.clear if settings.reload_templates
@ -1086,7 +1087,7 @@ module Sinatra
# Dispatch a request with error handling.
def dispatch!
force_encoding(@params = IndifferentHash[@request.params])
force_encoding(@params.merge!(@request.params))
invoke do
static! if settings.static? && (request.get? || request.head?)

View file

@ -201,6 +201,21 @@ class RoutingTest < Minitest::Test
assert_equal "This is not a drill either", response.body
end
it "captures the custom exception message of a BadRequest" do
mock_app {
get('/') {}
error Sinatra::BadRequest do
'This is not a drill either'
end
}
get "/", "foo" => "", "foo[]" => ""
assert_equal "26", response["Content-Length"]
assert_equal 400, status
assert_equal "This is not a drill either", response.body
end
it "uses 404 error handler for not matching route" do
mock_app {
not_found do