error! not finding Grape::Entity if called in rescue_from block
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
Example:
class Api::Post < Grape::API
rescue_from StandardError do
error!('Message' 404)
end
resource :post do
desc '' do
failure [[404, 'Not found', Api::Entity::Error]]
end
get :working_example do
error!('Message' 404)
end
get :not_working_example do
raise StandardError
end
end
end
As I understood, calling error! from rescue_from results being in context of Grape::Middleware::Error, thus env['api.endpoint'].status is nil. While calling error! from get do ; end works just fine because of the env['api.endpoint'].status being properly set already in Grape::DSL::InsideRoute. So in the first case Grape is not able to find the Entity responsible for the error (see https://github.com/intridea/grape/blob/master/lib/grape/error_formatter/base.rb#L42).
Can anyone confirm that it is an expected behavior?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the working and non-working examples from the issue, then inspect lib/grape/error_formatter/base.rb at the referenced line and compare the Grape::Middleware::Error and Grape::DSL::InsideRoute paths. Done means establishing whether rescue_from should resolve the declared Api::Entity::Error and, if so, adding coverage for the rescue_from case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100