Exception: Rakuten::ApiError

Inherits:
Error
  • Object
show all
Defined in:
lib/rakuten/api_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, help = nil) ⇒ ApiError

Returns a new instance of ApiError.



10
11
12
13
# File 'lib/rakuten/api_error.rb', line 10

def initialize message, help = nil
  @help = help
  super message
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



8
9
10
# File 'lib/rakuten/api_error.rb', line 8

def help
  @help
end

Class Method Details

.[](code) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rakuten/api_error.rb', line 16

def [] code
  code = code.to_i
  return self if code == 0

  @errors_by_code ||= Hash.new do |hash, key|
    error_class = Class.new(self).tap { |c| c.code = key }
    const_set "E#{key}", error_class
    hash[key] = error_class
  end

  @errors_by_code[code]
end