Skip to content

Commit d8a0d7a

Browse files
committed
permit string response if that's the content-type
1 parent 3d57caa commit d8a0d7a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ class RaiseError < ::Faraday::Middleware
77
def on_complete(env)
88
raise Slack::Web::Api::Errors::TooManyRequestsError, env.response if env.status == 429
99

10+
response_content_type_is_string = env.response&.headers&.[]('content-type')&.include?('text/plain') || false
11+
12+
raise ::Faraday::ParsingError.new(nil, env.response) if !response_content_type_is_string && !env.body.is_a?(Hash)
13+
1014
return unless env.success?
1115

1216
body = env.body
13-
return if env.success? && body.is_a?(String)
17+
return if env.success? && body.is_a?(String) && response_content_type_is_string
1418
return unless body
1519
return if body['ok']
1620

spec/slack/web/client_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@
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)
299298
end
300299
end
301300

@@ -306,7 +305,6 @@
306305
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
307306
expect(exception.response.body).to eq('{')
308307
expect(exception.cause).to be_a(Faraday::ParsingError)
309-
expect(exception.cause.cause).to be_a(JSON::ParserError)
310308
end
311309
end
312310
end

0 commit comments

Comments
 (0)