Sha256: bf2ea74e29f1c751c27496a3c2438b56e9c946ebba21ad6303205bce5397e008

Contents?: true

Size: 776 Bytes

Versions: 6

Compression:

Stored size: 776 Bytes

Contents

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
slack-ruby-client-2.4.0 lib/slack/web/faraday/response/raise_error.rb
slack-ruby-client-2.3.0 lib/slack/web/faraday/response/raise_error.rb
slack-ruby-client-2.2.0 lib/slack/web/faraday/response/raise_error.rb
slack-ruby-client-2.1.0 lib/slack/web/faraday/response/raise_error.rb
slack-ruby-client-2.0.0 lib/slack/web/faraday/response/raise_error.rb
slack-ruby-client-1.1.0 lib/slack/web/faraday/response/raise_error.rb