Skip to content
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

Allow headers set in before block to be passed to ValidationErrors #1062

Closed
yairgo opened this issue Jul 10, 2015 · 2 comments
Closed

Allow headers set in before block to be passed to ValidationErrors #1062

yairgo opened this issue Jul 10, 2015 · 2 comments

Comments

@yairgo
Copy link
Contributor

yairgo commented Jul 10, 2015

I'm using grape with grape-swagger and swagger-ui and for swagger-ui to work I need to set header values like so:

before do
  header['Access-Control-Allow-Origin'] = '*'
  header['Access-Control-Request-Method'] = '*'
end

When using parameter validations and submitting a request with invalid params, I've lost the context in which those headers were set. This causes swagger-ui to not be able to render the response.

rescue_from Grape::Exceptions::ValidationErrors do |e|
  # Headers not available here
  error!('my custom error message', 400)
end

I'm going to put in a pull request to add the headers to Grape::Exceptions::ValidationExceptions class so that I can do this

rescue_from Grape::Exceptions::ValidationErrors do |e|
  error!('my custom error message', 400, e.headers)
end
@yairgo
Copy link
Contributor Author

yairgo commented Jul 13, 2015

dblock thanks for the quick turnaround on this.

@dm1try
Copy link
Member

dm1try commented Aug 20, 2015

Fixed in #1063.

@dm1try dm1try closed this as completed Aug 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants