Module: CdekClient::Calculator

Defined in:
lib/cdek_client/calculator_errors.rb

Defined Under Namespace

Classes: APIError, ApiVersionError, AuthError, DateEmptyError, DecodeError, DeliveryImpossibleError, DeliveryTypeError, Error, FormatError, PlaceEmptyError, PlaceParamsError, ReceiverCityEmptyError, ReceiverPostcodeAmbigiousError, ReceiverPostcodeNotFoundError, SenderCityEmptyError, SenderPostcodeAmbigiousError, SenderPostcodeNotFoundError, ServerError, TariffEmptyError, UnkownAPIError

Constant Summary collapse

API_ERROR_MAPPINGS =
{
  0 => ServerError,
  1 => ApiVersionError,
  2 => AuthError,
  3 => DeliveryImpossibleError,
  4 => PlaceParamsError,
  5 => PlaceEmptyError,
  6 => TariffEmptyError,
  7 => SenderCityEmptyError,
  8 => ReceiverCityEmptyError,
  9 => DateEmptyError,
  10 => DeliveryTypeError,
  11 => FormatError,
  12 => DecodeError,
  13 => SenderPostcodeNotFoundError,
  14 => SenderPostcodeAmbigiousError,
  15 => ReceiverPostcodeNotFoundError,
  16 => ReceiverPostcodeAmbigiousError
}

Class Method Summary collapse

Class Method Details

.get_api_error(code, message) ⇒ Object



46
47
48
49
50
# File 'lib/cdek_client/calculator_errors.rb', line 46

def self.get_api_error(code, message)
  code = code.to_i if !code.is_a?(Integer) && code.to_s =~ /^\d+$/ 
  klass = API_ERROR_MAPPINGS[code] || UnkownAPIError
  klass.new code, message
end