Class: Washbullet::HttpException

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/washbullet/http_exception.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
25
26
27
# File 'lib/washbullet/http_exception.rb', line 10

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