Sha256: 910cd0cee471f059ca1a1ed70f7c7f303dada88e4b47469f9ccec02b7154e1e4

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

module Edmunds
  class Error < StandardError

    BadRequest = Class.new self
    Unauthorized = Class.new self
    Forbidden = Class.new self
    NotFound = Class.new self
    InternalServerError = Class.new self
    BadGateway = Class.new self
    ServiceUnavailable = Class.new self
    GatewayTimeout = Class.new self
    Unknown = Class.new self

    ERRORS = {
      400 => Edmunds::Error::BadRequest,
      401 => Edmunds::Error::Unauthorized,
      403 => Edmunds::Error::Forbidden,
      404 => Edmunds::Error::NotFound,
      500 => Edmunds::Error::InternalServerError,
      502 => Edmunds::Error::BadGateway,
      503 => Edmunds::Error::ServiceUnavailable,
      504 => Edmunds::Error::GatewayTimeout
    }.freeze


    def self.from_response(code, body)
      message = "\nHTTP response code: #{code}. "
      if body['message']
        message << "HTTP message: #{body['message']}"
      else
        message << "No message in http body.\nHTTP body: #{body}"
      end
      new message
    end

    def initialize(message)
      super message
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
edmunds_api-0.1.8 lib/edmunds/error.rb
edmunds_api-0.1.7 lib/edmunds/error.rb
edmunds_api-0.1.6 lib/edmunds/error.rb
edmunds_api-0.1.5 lib/edmunds/error.rb
edmunds_api-0.1.4 lib/edmunds/error.rb
edmunds_api-0.1.3 lib/edmunds/error.rb