Exception: OJElectronics::Client::AuthenticationError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/oj_electronics/client.rb

Direct Known Subclasses

IncorrectPasswordError, InvalidUsernameError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_code, message = nil) ⇒ AuthenticationError

Returns a new instance of AuthenticationError.



24
25
26
27
# File 'lib/oj_electronics/client.rb', line 24

def initialize(error_code, message = nil)
  @error_code = error_code
  super(message || "Unable to authenticate: ErrorCode #{error_code}")
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



22
23
24
# File 'lib/oj_electronics/client.rb', line 22

def error_code
  @error_code
end

Class Method Details

.create(error_code) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/oj_electronics/client.rb', line 11

def create(error_code)
  klass, message = case error_code
                   when 1 then [InvalidUsernameError, "Invalid Username"]
                   when 2 then [IncorrectPasswordError, "Incorrect password"]
                   else
                     [self, nil]
                   end
  klass.new(error_code, message)
end