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

Merge pull request #1351 from jkowens/fix-1350

Fix issue with custom error handler on bad request
This commit is contained in:
namusyaka 2018-02-07 02:35:39 +09:00 committed by GitHub
commit d661739853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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
@ -1087,7 +1088,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