Sha256: ea5113aae5fb180a44479327c8ba07489b6033c4d685fa2341a4ea175ac6a497

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

class Mrkt::Errors
  class Error < StandardError
  end

  def self.create_class
    Class.new(Error)
  end

  Unknown = create_class
  EmptyResponse = create_class
  AuthorizationError = create_class

  RESPONSE_CODE_TO_ERROR = {
    413  => 'RequestEntityTooLarge',
    600  => 'EmptyAccessToken',
    601  => 'AccessTokenInvalid',
    602  => 'AccessTokenExpired',
    603  => 'AccessDenied',
    604  => 'RequestTimedOut',
    605  => 'HTTPMethodNotSupported',
    606  => 'MaxRateLimit',
    607  => 'DailyQuotaReached',
    608  => 'APITemporarilyUnavailable',
    609  => 'InvalidJSON',
    610  => 'RequestedResourceNotFound',
    611  => 'System',
    612  => 'InvalidContentType',
    703  => 'DisabledFeature',
    1001 => 'TypeMismatch',
    1002 => 'MissingParamater',
    1003 => 'UnspecifiedAction',
    1004 => 'LeadNotFound',
    1005 => 'LeadAlreadyExists',
    1006 => 'FieldNotFound',
    1007 => 'MultipleLeadsMatching',
    1008 => 'PartitionAccessDenied',
    1009 => 'PartitionNameUnspecified',
    1010 => 'PartitionUpdateDenied',
    1011 => 'FieldNotSupported',
    1012 => 'InvalidCookieValue',
    1013 => 'ObjectNotFound',
    1014 => 'FailedToCreateObject'
  }

  RESPONSE_CODE_TO_ERROR.values.each do |class_name|
    const_set(class_name, create_class)
  end

  def self.find_by_response_code(response_code)
    const_get(RESPONSE_CODE_TO_ERROR.fetch(response_code, 'Error'))
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mrkt-0.9.0 lib/mrkt/errors.rb
mrkt-0.8.0 lib/mrkt/errors.rb
mrkt-0.7.0 lib/mrkt/errors.rb
mrkt-0.6.2 lib/mrkt/errors.rb
mrkt-0.6.1 lib/mrkt/errors.rb
mrkt-0.6.0 lib/mrkt/errors.rb
mrkt-0.5.0 lib/mrkt/errors.rb
mrkt-0.4.0 lib/mrkt/errors.rb