Class: Slack::Web::Faraday::Response::RaiseError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/slack/web/faraday/response/raise_error.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
# File 'lib/slack/web/faraday/response/raise_error.rb', line 24

def call(env)
  super
rescue ::Faraday::ParsingError
  raise Slack::Web::Api::Errors::ParsingError.new('parsing_error', env.response)
end

#on_complete(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/slack/web/faraday/response/raise_error.rb', line 7

def on_complete(env)
  raise Slack::Web::Api::Errors::TooManyRequestsError, env.response if env.status == 429

  return unless env.success?

  body = env.body
  return unless body
  return if body['ok']

  error_message =
    body['error'] || body['errors'].map { |message| message['error'] }.join(',')

  error_class = Slack::Web::Api::Errors::ERROR_CLASSES[error_message]
  error_class ||= Slack::Web::Api::Errors::SlackError
  raise error_class.new(error_message, env.response)
end