ruby-grape / ruby-grape/grape

Access the error_response in the middleware after method

Open
#1,301 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

Hi,
I'm maintaining a fork of this repos : https://github.com/aserafin/grape_logging

Since v0.14.1, Grape ensure that the middleware after method is always call even if an exception occurs. This is a great functionality for us because now we can log failed requests.

But when the @app.call(@env) fail here : https://github.com/ruby-grape/grape/blob/master/lib/grape/middleware/base.rb#L30
then the call to the response method in the middleware will fail because it will try to to that @app_response[2] at this line : https://github.com/ruby-grape/grape/blob/master/lib/grape/middleware/base.rb#L58 but @app_response is nil.

My question is: how do I access to the error_response (or the thing that contains the error answer) in my middleware when an error!("something", 404) is called in the endpoint ? Is it possible ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/grape/middleware/base.rb at the referenced lines 30 and 58, then trace how the middleware after method handles failures from @app.call(@env). Determine how an error_response from error!("something", 404) should be exposed to middleware and add coverage for that failure path; done means the middleware can access the error response without response failing.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.