Skip to content

Commit 629de08

Browse files
committed
revert raise_error.rb
1 parent 6792106 commit 629de08

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

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

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,14 @@ module Web
44
module Faraday
55
module Response
66
class RaiseError < ::Faraday::Middleware
7-
def raise_if_too_many_requests!(env)
7+
def on_complete(env)
88
raise Slack::Web::Api::Errors::TooManyRequestsError, env.response if env.status == 429
9-
end
10-
11-
def raise_if_response_is_invalid_json!(env)
12-
return if response_content_type_is_a_string?(env) || env.body.is_a?(Hash)
13-
14-
begin
15-
raise JSON::ParserError
16-
rescue StandardError => e
17-
raise ::Faraday::ParsingError.new(e, env.response)
18-
end
19-
end
20-
21-
def response_content_type_is_a_string?(env)
22-
env.response&.headers&.[]('content-type')&.include?('text/plain') || false
23-
end
24-
25-
def should_return?(env)
26-
body = env.body
27-
return true unless env.success?
28-
return true if env.success? && body.is_a?(String) && response_content_type_is_a_string?(env)
29-
return true if !body || body['ok']
309

31-
false
32-
end
33-
34-
def on_complete(env)
35-
raise_if_too_many_requests!(env)
36-
raise_if_response_is_invalid_json!(env)
10+
return unless env.success?
3711

3812
body = env.body
39-
return if should_return?(env)
13+
return unless body
14+
return if body['ok']
4015

4116
error_message = body['error'] || body['errors'].map { |message| message['error'] }.join(',')
4217
error_class = Slack::Web::Api::Errors::ERROR_CLASSES[error_message]

0 commit comments

Comments
 (0)