diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 20f68ace..5f195f71 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -876,9 +876,11 @@ module Sinatra # Define a custom error handler. Optionally takes either an Exception # class, or an HTTP status code to specify which errors should be # handled. - def error(codes = Exception, &block) - args = compile! "ERROR", //, block - Array(codes).each { |c| @errors[c] = args } + def error(*codes, &block) + args = compile! "ERROR", //, block + codes = codes.map { |c| Array(c) }.flatten + codes << Exception if codes.empty? + codes.each { |c| @errors[c] = args } end # Sugar for `error(404) { ... }` diff --git a/test/mapped_error_test.rb b/test/mapped_error_test.rb index 2a8a7852..accf4e81 100644 --- a/test/mapped_error_test.rb +++ b/test/mapped_error_test.rb @@ -202,6 +202,19 @@ class MappedErrorTest < Test::Unit::TestCase assert_equal 'Error: 507', body end + it 'allows passing more than one range' do + mock_app { + set :raise_errors, false + error(409..411, 503..509) { "Error: #{response.status}" } + get '/' do + [507, {}, 'A very special error'] + end + } + get '/' + assert_equal 507, status + assert_equal 'Error: 507', body + end + class FooError < RuntimeError end