Merge pull request #1351 from jkowens/fix-1350
Fix issue with custom error handler on bad request
This commit is contained in:
commit
d661739853
|
@ -915,6 +915,7 @@ module Sinatra
|
||||||
|
|
||||||
def call!(env) # :nodoc:
|
def call!(env) # :nodoc:
|
||||||
@env = env
|
@env = env
|
||||||
|
@params = IndifferentHash.new
|
||||||
@request = Request.new(env)
|
@request = Request.new(env)
|
||||||
@response = Response.new
|
@response = Response.new
|
||||||
template_cache.clear if settings.reload_templates
|
template_cache.clear if settings.reload_templates
|
||||||
|
@ -1087,7 +1088,7 @@ module Sinatra
|
||||||
|
|
||||||
# Dispatch a request with error handling.
|
# Dispatch a request with error handling.
|
||||||
def dispatch!
|
def dispatch!
|
||||||
force_encoding(@params = IndifferentHash[@request.params])
|
force_encoding(@params.merge!(@request.params))
|
||||||
|
|
||||||
invoke do
|
invoke do
|
||||||
static! if settings.static? && (request.get? || request.head?)
|
static! if settings.static? && (request.get? || request.head?)
|
||||||
|
|
|
@ -201,6 +201,21 @@ class RoutingTest < Minitest::Test
|
||||||
assert_equal "This is not a drill either", response.body
|
assert_equal "This is not a drill either", response.body
|
||||||
end
|
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
|
it "uses 404 error handler for not matching route" do
|
||||||
mock_app {
|
mock_app {
|
||||||
not_found do
|
not_found do
|
||||||
|
|
Loading…
Reference in New Issue