Skip to content

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

Closed
@yairgo

Description

@yairgo

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions