Skip to content

Error when rescue Grape::Exceptions::ValidationErrors in json format with backtrance and original_exception #2472

Closed
@ericproulx

Description

@ericproulx

Following #2471, I found that this case is raising an error.

describe 'rescue Grape::Exceptions::ValidationErrors in json format with backtrace and original_exception' do
  let(:app) do
    Class.new(Grape::API) do
      format :json

      rescue_from Grape::Exceptions::ValidationErrors, backtrace: true, original_exception: true do |e|
        error!(e, 418, {}, e.backtrace, e)
      end

      params do
        requires :beer
      end

      get '/' do
      end
    end
  end

  before { get '/' }

  context 'with json response type format' do
    subject { last_response.status }

    it { is_expected.to eq(418) }
  end
end

Our README shows the same kind of example but without original_exception and backtrace.

Nonetheless, It works for XML and TXT because of the simple ternary condition while JSON is doing something different when Grape::Exceptions::ValidationErrors

If we want to add original_exception and backtrace I think we'll need to enhance Grape::Exceptions::ValidationErrors with a new function to include its when dumping JSON.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions