Sha256: b4da5f999bc1bf28e497fbc482c5f76a7da1f16d67090d9c479c17511af19e22

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module Washbullet
  class BadRequest    < StandardError; end
  class Unauthorized  < StandardError; end
  class RequestFailed < StandardError; end
  class Forbidden     < StandardError; end
  class NotFound      < StandardError; end
  class ServerError   < StandardError; end

  class HttpException < Faraday::Response::Middleware
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
washbullet-0.3.1 lib/washbullet/http_exception.rb
washbullet-0.3.0 lib/washbullet/http_exception.rb