Exception: Boxr::BoxrError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/boxr/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status: nil, body: nil, header: nil, boxr_message: nil) ⇒ BoxrError

Returns a new instance of BoxrError.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/boxr/errors.rb', line 7

def initialize(status: nil, body: nil, header: nil, boxr_message: nil)
  @status = status
  @response_body = body
  @header = header
  @boxr_message = boxr_message

  if(body)
    begin
      body_json = JSON.load(body)

      if body_json
        @type = body_json["type"]
        @box_status = body_json["status"]
        @code = body_json["code"]
        @help_uri = body_json["help_uri"]
        @box_message = body_json["message"]
        @request_id = body_json["request_id"]
      end
    rescue
    end
  end
end

Instance Attribute Details

#box_messageObject (readonly)

Returns the value of attribute box_message.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def box_message
  @box_message
end

#boxr_messageObject (readonly)

Returns the value of attribute boxr_message.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def boxr_message
  @boxr_message
end

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def code
  @code
end

#help_uriObject (readonly)

Returns the value of attribute help_uri.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def help_uri
  @help_uri
end

#request_idObject (readonly)

Returns the value of attribute request_id.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def request_id
  @request_id
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def response_body
  @response_body
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/boxr/errors.rb', line 5

def type
  @type
end

Instance Method Details

#messageObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/boxr/errors.rb', line 30

def message
  auth_header = @header['WWW-Authenticate'][0] unless @header.nil?
  if(auth_header && auth_header != [])
    "#{@status}: #{auth_header}"
  elsif(@box_message)
    "#{@status}: #{@box_message}"
  elsif(@boxr_message)
    @boxr_message
  else
    "#{@status}: #{@response_body}"
  end
end

#to_sObject



43
44
45
# File 'lib/boxr/errors.rb', line 43

def to_s
  message
end