Class: ShellEv::UnauthorizedException

Inherits:
APIException
  • Object
show all
Defined in:
lib/shell_ev/exceptions/unauthorized_exception.rb

Overview

Unauthorized class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, response) ⇒ UnauthorizedException

The constructor.

Parameters:

  • reason (String)

    The reason for raising an exception.

  • response (HttpResponse)

    The HttpReponse of the API call.



27
28
29
30
31
# File 'lib/shell_ev/exceptions/unauthorized_exception.rb', line 27

def initialize(reason, response)
  super(reason, response)
  hash = APIHelper.json_deserialize(@response.raw_body)
  unbox(hash)
end

Instance Attribute Details

#errorsArray[UnauthorizedErrMsg]

Exception details of the error

Returns:



22
23
24
# File 'lib/shell_ev/exceptions/unauthorized_exception.rb', line 22

def errors
  @errors
end

#request_idString

requestId or correlation id of the message

Returns:

  • (String)


14
15
16
# File 'lib/shell_ev/exceptions/unauthorized_exception.rb', line 14

def request_id
  @request_id
end

#statusString

Status of the request

Returns:

  • (String)


18
19
20
# File 'lib/shell_ev/exceptions/unauthorized_exception.rb', line 18

def status
  @status
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



60
61
62
63
64
# File 'lib/shell_ev/exceptions/unauthorized_exception.rb', line 60

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} request_id: #{@request_id.inspect}, status: #{@status.inspect}, errors:"\
  " #{@errors.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



54
55
56
57
# File 'lib/shell_ev/exceptions/unauthorized_exception.rb', line 54

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} request_id: #{@request_id}, status: #{@status}, errors: #{@errors}>"
end

#unbox(hash) ⇒ Object

Populates this object by extracting properties from a hash. response body.

Parameters:

  • hash (Hash)

    The deserialized response sent by the server in the



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shell_ev/exceptions/unauthorized_exception.rb', line 36

def unbox(hash)
  return nil unless hash

  @request_id = hash.key?('requestId') ? hash['requestId'] : SKIP
  @status = hash.key?('status') ? hash['status'] : SKIP
  # Parameter is an array, so we need to iterate through it
  @errors = nil
  unless hash['errors'].nil?
    @errors = []
    hash['errors'].each do |structure|
      @errors << (UnauthorizedErrMsg.from_hash(structure) if structure)
    end
  end

  @errors = SKIP unless hash.key?('errors')
end