Exception: DataComApi::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/data-com-api/errors.rb

Constant Summary collapse

API_HTTP_STATUS_CODE =
0
API_ERROR_CODE =
'no error code provided'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, options = {}) ⇒ Error

Returns a new instance of Error.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/data-com-api/errors.rb', line 14

def initialize(msg=nil, options={})
  options = options.reverse_merge({
    http_status_code: nil,
    api_stack_trace:  nil,
    error_code:       nil
  })

  @http_status_code ||= options[:http_status_code] || self.class::API_HTTP_STATUS_CODE
  @api_stack_trace  ||= options[:api_stack_trace]
  @error_code       ||= options[:error_code] || self.class::API_ERROR_CODE

  super(msg)
end

Instance Attribute Details

#api_stack_traceObject (readonly)

Returns the value of attribute api_stack_trace.



11
12
13
# File 'lib/data-com-api/errors.rb', line 11

def api_stack_trace
  @api_stack_trace
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



12
13
14
# File 'lib/data-com-api/errors.rb', line 12

def error_code
  @error_code
end

#http_status_codeObject (readonly)

Returns the value of attribute http_status_code.



10
11
12
# File 'lib/data-com-api/errors.rb', line 10

def http_status_code
  @http_status_code
end

Class Method Details

.from_code(error_code_str) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/data-com-api/errors.rb', line 28

def self.from_code(error_code_str)
  case error_code_str
  when ParamError::API_ERROR_CODE             then ParamError
  when LoginFailError::API_ERROR_CODE         then LoginFailError
  when TokenFailError::API_ERROR_CODE         then TokenFailError
  when PurchaseLowPointsError::API_ERROR_CODE then PurchaseLowPointsError
  when ContactNotExistError::API_ERROR_CODE   then ContactNotExistError
  when ContactNotOwnedError::API_ERROR_CODE   then ContactNotOwnedError
  when SearchError::API_ERROR_CODE            then SearchError
  when SysError::API_ERROR_CODE               then SysError
  when NotImplementedError::API_ERROR_CODE    then NotImplementedError
  when NotAvailableError::API_ERROR_CODE      then NotAvailableError
  else Error
  end
end