From 2eabc9bfe2415cf3891b24e81a5c503a8ad99b30 Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Wed, 3 Jul 2024 14:33:46 +0200 Subject: [PATCH] Add spec --- spec/grape/api_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index b67dcbe24e..93d72ea70e 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -2394,7 +2394,7 @@ class ChildError < ParentError; end end end - describe '.error_format' do + describe '.error_formatter' do it 'rescues all errors and return :txt' do subject.rescue_from :all subject.format :txt @@ -2460,6 +2460,18 @@ def self.call(message, _backtrace, _options, _env, _original_exception) get '/exception' expect(last_response.body).to eq('message: rain! @backtrace') end + + it 'returns a modified error with a custom error format' do + subject.rescue_from :all, backtrace: true do |e| + error!("raining dogs and cats", 418, {}, e.backtrace, e) + end + subject.error_formatter :txt, ApiSpec::CustomErrorFormatter + subject.get '/exception' do + raise 'rain!' + end + get '/exception' + expect(last_response.body).to eq('message: raining dogs and cats @backtrace') + end end describe 'with' do