Exception: Boxr::BoxrException

Inherits:
Exception
  • Object
show all
Defined in:
lib/boxr/exceptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, header) ⇒ BoxrException

Returns a new instance of BoxrException.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/boxr/exceptions.rb', line 7

def initialize(status,body,header)
	@status = status
	@response_body = body
	@header = header

	body_json = Oj.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
end

Instance Attribute Details

#box_messageObject (readonly)

Returns the value of attribute box_message.



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

def box_message
  @box_message
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#help_uriObject (readonly)

Returns the value of attribute help_uri.



5
6
7
# File 'lib/boxr/exceptions.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/exceptions.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/exceptions.rb', line 5

def response_body
  @response_body
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#messageObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/boxr/exceptions.rb', line 23

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

#to_sObject



34
35
36
# File 'lib/boxr/exceptions.rb', line 34

def to_s
	message
end