spec/grape/middleware/formatter_spec.rb in grape-1.0.0 vs spec/grape/middleware/formatter_spec.rb in grape-1.0.1
- old
+ new
@@ -322,6 +322,30 @@
env = { 'PATH_INFO' => '/hello.invalid', 'HTTP_ACCEPT' => 'application/x-invalid' }
_, _, bodies = *subject.call(env)
expect(bodies.body.first).to eq({ message: 'invalid' }.to_json)
end
end
+
+ context 'custom parser raises exception and rescue options are enabled for backtrace and original_exception' do
+ it 'adds the backtrace and original_exception to the error output' do
+ subject = Grape::Middleware::Formatter.new(
+ app,
+ rescue_options: { backtrace: true, original_exception: true },
+ parsers: { json: ->(_object, _env) { raise StandardError, 'fail' } }
+ )
+ io = StringIO.new('{invalid}')
+ error = catch(:error) {
+ subject.call(
+ 'PATH_INFO' => '/info',
+ 'REQUEST_METHOD' => 'POST',
+ 'CONTENT_TYPE' => 'application/json',
+ 'rack.input' => io,
+ 'CONTENT_LENGTH' => io.length
+ )
+ }
+
+ expect(error[:message]).to eq 'fail'
+ expect(error[:backtrace].size).to be >= 1
+ expect(error[:original_exception].class).to eq StandardError
+ end
+ end
end