Skip to content

Commit 958db8f

Browse files
committed
properly raise nested exception
1 parent 439bf88 commit 958db8f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/slack/web/faraday/response/raise_error.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ def raise_if_too_many_requests!(env)
1111
def raise_if_response_is_invalid_json!(env)
1212
return if response_content_type_is_a_string?(env) || env.body.is_a?(Hash)
1313

14-
raise ::Faraday::ParsingError.new(nil, env.response)
14+
begin
15+
raise JSON::ParserError
16+
rescue StandardError => e
17+
raise ::Faraday::ParsingError.new(e, env.response)
18+
end
1519
end
1620

1721
def response_content_type_is_a_string?(env)

spec/slack/web/client_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@
295295
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
296296
expect(exception.response.body).to eq('<html></html>')
297297
expect(exception.cause).to be_a(Faraday::ParsingError)
298+
expect(exception.cause.cause).to be_a(JSON::ParserError)
298299
end
299300
end
300301

@@ -305,6 +306,7 @@
305306
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
306307
expect(exception.response.body).to eq('{')
307308
expect(exception.cause).to be_a(Faraday::ParsingError)
309+
expect(exception.cause.cause).to be_a(JSON::ParserError)
308310
end
309311
end
310312
end

0 commit comments

Comments
 (0)