Class: PushbulletRuby::HttpException

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/pushbullet_ruby/http_exeption.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pushbullet_ruby/http_exeption.rb', line 10

def call(env)
  @app.call(env).on_complete do |response|
    exception =
        case response.status
          when 400      then PushbulletRuby::BadRequest
          when 401      then PushbulletRuby::Unauthorized
          when 402      then PushbulletRuby::RequestFailed
          when 403      then PushbulletRuby::Forbidden
          when 404      then PushbulletRuby::NotFound
          when 500..505 then PushbulletRuby::ServerError
        end

    raise exception, error_message(response.body) if exception
  end
end