Sha256: d67d90cb773f00c9f35dc7c7739a0d0b6c824174ade11029e4dc07ead89c6249

Contents?: true

Size: 905 Bytes

Versions: 2

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

Dir[File.join(__dir__, 'errors', '**', '*.rb')].each { |f| require_relative f }

module Easyship
  # Represents a mapping of HTTP status codes to Easyship-specific classes
  class Error
    # rubocop:disable Style::MutableConstant Style::MissingElse
    ERRORS = {
      400 => Easyship::Errors::BadRequestError,
      401 => Easyship::Errors::InvalidTokenError,
      402 => Easyship::Errors::PaymentRequiredError,
      404 => Easyship::Errors::ResourceNotFoundError,
      422 => Easyship::Errors::UnprocessableContentError,
      429 => Easyship::Errors::RateLimitError
    }

    ERRORS.default_proc = proc do |_hash, key|
      case key.to_s
      when /4\d{2}/
        Easyship::Errors::ClientError
      when /5\d{2}/
        Easyship::Errors::ServerError
      end
    end
    # rubocop:enable Style::MutableConstant Style::MissingElse

    ERRORS.freeze
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
easyship-0.1.4 lib/easyship/error.rb
easyship-0.1.3 lib/easyship/error.rb