Class: Pushbullet::HttpException

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/pushbullet/http_exception.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pushbullet/http_exception.rb', line 12

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
    when 400
      raise Pushbullet::BadRequest,    'Often missing a required parameter'
    when 401
      raise Pushbullet::Unauthorized,  'No valid API key provided'
    when 402
      raise Pushbullet::RequestFailed, 'Parameters were valid but the request failed'
    when 403
      raise Pushbullet::Forbidden,     'The API key is not valid for that request'
    when 404
      raise Pushbullet::NotFound,      'The requested item doesn\'t exist'
    when 500..505
      raise Pushbullet::ServerError,   'Something went wrong on PushBullet\'s side'
    end
  end
end