Sha256: 97dfc4154042a7ca98419bd3d68851a913373def7b4f332d90c53a661eff809b

Contents?: true

Size: 658 Bytes

Versions: 12

Compression:

Stored size: 658 Bytes

Contents

require 'faraday'

module Ably
  module Rest
    module Middleware
      # HTTP exceptions raised due to a status code error on a 3rd party site
      # Used by auth calls
      class ExternalExceptions < Faraday::Middleware
        def on_complete(env)
          if env.status >= 400
            error_status_code = env.status
            message = "Error #{error_status_code}: #{(env.body || '')[0...200]}"

            if error_status_code >= 500
              raise Ably::Exceptions::ServerError, message
            else
              raise Ably::Exceptions::InvalidRequest, message
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
ably-rest-1.2.7 lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb
ably-1.2.7 lib/ably/rest/middleware/external_exceptions.rb
ably-rest-1.2.6 lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb
ably-1.2.6 lib/ably/rest/middleware/external_exceptions.rb
ably-rest-1.2.4 lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb
ably-1.2.4 lib/ably/rest/middleware/external_exceptions.rb
ably-rest-1.2.3 lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb
ably-1.2.3 lib/ably/rest/middleware/external_exceptions.rb
ably-rest-1.2.2 lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb
ably-1.2.2 lib/ably/rest/middleware/external_exceptions.rb
ably-rest-1.2.1 lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb
ably-1.2.1 lib/ably/rest/middleware/external_exceptions.rb