Class: Ably::Rest::Middleware::ExternalExceptions

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb

Overview

HTTP exceptions raised due to a status code error on a 3rd party site Used by auth calls

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb', line 9

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