Sha256: e17623b784d6e069e430fa35a518a55db5df1ba44b4a2c0b98b3ef9d921ce9b5

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require 'faraday'

module Pushbullet
  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 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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pushbullet-0.0.4 lib/pushbullet/http_exception.rb
pushbullet-0.0.2 lib/pushbullet/http_exception.rb