Exception: Boxr::BoxrError
- Inherits:
-
StandardError
- Object
- StandardError
- Boxr::BoxrError
- Defined in:
- lib/boxr/errors.rb
Instance Attribute Summary collapse
-
#box_message ⇒ Object
readonly
Returns the value of attribute box_message.
-
#boxr_message ⇒ Object
readonly
Returns the value of attribute boxr_message.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#help_uri ⇒ Object
readonly
Returns the value of attribute help_uri.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(status: nil, body: nil, header: nil, boxr_message: nil) ⇒ BoxrError
constructor
A new instance of BoxrError.
- #message ⇒ Object
- #to_s ⇒ Object
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 = 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_message ⇒ Object (readonly)
Returns the value of attribute box_message.
5 6 7 |
# File 'lib/boxr/errors.rb', line 5 def @box_message end |
#boxr_message ⇒ Object (readonly)
Returns the value of attribute boxr_message.
5 6 7 |
# File 'lib/boxr/errors.rb', line 5 def @boxr_message end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/boxr/errors.rb', line 5 def code @code end |
#help_uri ⇒ Object (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_id ⇒ Object (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_body ⇒ Object (readonly)
Returns the value of attribute response_body.
5 6 7 |
# File 'lib/boxr/errors.rb', line 5 def response_body @response_body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/boxr/errors.rb', line 5 def status @status end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/boxr/errors.rb', line 5 def type @type end |
Instance Method Details
#message ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/boxr/errors.rb', line 33 def 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_s ⇒ Object
48 49 50 |
# File 'lib/boxr/errors.rb', line 48 def to_s end |