Class: ClientErrorResponse
- Inherits:
-
Object
- Object
- ClientErrorResponse
- Defined in:
- lib/hyperion/types/client_error_response.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
The structure expected in a 400 response.
-
#content ⇒ Object
readonly
- String, nil
-
Optional content to return; may be an application-specific description of the error.
-
#errors ⇒ Object
readonly
- Array<ClientErrorDetail>
-
Structured information with error specifics.
-
#message ⇒ Object
readonly
- String
-
An error message that can be presented to the user.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(*_args) ⇒ Object
-
#initialize(message, errors, code = nil, content = nil) ⇒ ClientErrorResponse
constructor
A new instance of ClientErrorResponse.
Constructor Details
#initialize(message, errors, code = nil, content = nil) ⇒ ClientErrorResponse
Returns a new instance of ClientErrorResponse.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hyperion/types/client_error_response.rb', line 13 def initialize(, errors, code=nil, content=nil) Hyperion::Util.guard_param(, 'a message string', String) Hyperion::Util.guard_param(errors, 'an array of errors', &method(:error_array?)) code = ClientErrorCode.from(code || errors.first.try(:code) || ClientErrorCode::UNKNOWN) Hyperion::Util.guard_param(code, 'a code') { ClientErrorCode.values.include?(code) } @message = @code = code @errors = errors @content = content end |
Instance Attribute Details
#code ⇒ Object (readonly)
The structure expected in a 400 response.
8 9 10 |
# File 'lib/hyperion/types/client_error_response.rb', line 8 def code @code end |
#content ⇒ Object (readonly)
- String, nil
-
Optional content to return; may be an application-specific description of the error.
11 12 13 |
# File 'lib/hyperion/types/client_error_response.rb', line 11 def content @content end |
#errors ⇒ Object (readonly)
- Array<ClientErrorDetail>
-
Structured information with error specifics
10 11 12 |
# File 'lib/hyperion/types/client_error_response.rb', line 10 def errors @errors end |
#message ⇒ Object (readonly)
- String
-
An error message that can be presented to the user
9 10 11 |
# File 'lib/hyperion/types/client_error_response.rb', line 9 def @message end |
Class Method Details
.from_attrs(attrs) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hyperion/types/client_error_response.rb', line 34 def self.from_attrs(attrs) Hyperion::Util.nil_if_error do = attrs['message'] return nil if .blank? content = attrs['content'] code = code || ClientErrorCode.from(attrs['code']) errors = (attrs['errors'] || []).map(&ClientErrorDetail.method(:from_attrs)) self.new(, errors, code, content) end end |
Instance Method Details
#as_json(*_args) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/hyperion/types/client_error_response.rb', line 25 def as_json(*_args) { 'message' => , 'code' => code.value, 'errors' => errors.map(&:as_json), 'content' => content } end |