File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed
lib/slack/web/faraday/response Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
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
You can’t perform that action at this time.
0 commit comments