-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
I ran into the strange behaviour while refactoring my api and moving error handling into separate file. So I wrote this minimal example to reproduce the issue.
Here I use blocks to handle specific exceptions and call specific helper method:
class API < Grape::API
helpers do
def argument_error e
rack_response({ error: "argument_error_block" }.to_json)
end
def all_errors e
rack_response({ error: "all_errors_block" }.to_json)
end
end
rescue_from ArgumentError do |e| argument_error(e); end
rescue_from :all do |e| all_errors(e); end
get :argument_error do
raise ArgumentError
end
end
When I request /argument_error
API responds, as intended, with {"error":"argument_error_block"}
. But if I use with:
in rescue_from
rescue_from ArgumentError, with: :argument_error
rescue_from :all, with: :all_errors
I start to receive {"error":"all_errors_block"}
and never get to argument_error
helper.
Arugin and 42thcoder
Metadata
Metadata
Assignees
Labels
No labels