-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
headers set before error! is missing on response #1719
Comments
What are "your" headers? I think anything you set with You can set additional headers on error with error! 'Unauthorized', 401, 'X-Error-Detail' => 'Invalid token.' Lets clarify this for everyone. |
I have few headers that sent to user on every request in every action. I do not want to add them manually on each and every
based on request type, user and others. These headers can be different on each request by user or type. So, I would expect grape to respect my Problem is, before gets called but all headers set in before are gone. If this is an expected behavior then I will stick with middlewares. |
Does adding a header inside the API work? get do
header ...
errror!
end If it does, I think Care to write some specs? |
Note: If you want I can create an another branch with test in Expected: Both requests should pass. error_header_spec.rb:
|
Just pull request the failing spec please. Reduce the code a bit, there's a bunch of unnecessary stuff like versioning. Extend the spec to all the scenarios for |
@dblock, How is it look like now? (As I am new to this rspec world :)) I would like to get confirm before proper pull request |
I think i found a reason for that case.
on this stage there are no custom headers set. So the headers set in before callbacks are not reachable.
then |
The above PR does not totally address the issue, IMHO. Errors cannot only be raised by calling get do
Model.find(param[:id]) # may raise an ActiveRecord::NotFoundError
end or by Grape itsself during a POST request (i.e. before entering my code as defined in the endpoint's post-block) when the entity restricts certain attributes to have a state different from the one in which the attribute was posted. |
Can you write and PR a spec that describes this @meismann, please? |
This particular issue as described though, ie. headers set before @meismann Open a new issue with a spec for the scenario you're describing. |
Closed via #1869 |
Whenever I execute
error!()
, response does not contains my headers. In fact none of the headers likeX-Request-Id
. I presume this is due to calling a newRequest
instance and return that instead.How do I make sure that my important headers are in every request that grape gave? Even in
Rails::API
I am able to hold headers on any error.Of course, I could add my own Middleware. Is there any better or easy solution before middleware option?
The text was updated successfully, but these errors were encountered: