Sha256: 6d293cf165a55bbe41cbfd50b9a12d4ca8dbd15eb73172ca6a4ce1dd2fbf7037

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true
module Slack
  module Web
    module Faraday
      module Response
        class RaiseError < ::Faraday::Response::Middleware
          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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack-ruby-client-0.16.0 lib/slack/web/faraday/response/raise_error.rb