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.



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

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

  return unless body

  begin
    body_json = JSON.parse(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 JSON::ParserError
    # Ignore JSON parsing errors
  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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/boxr/errors.rb', line 33

def message
  unless @header.nil? || @header['WWW-Authenticate'].nil?
    auth_header = @header['WWW-Authenticate'][0]
  end
  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



48
49
50
# File 'lib/boxr/errors.rb', line 48

def to_s
  message
end