Exception: FunWithJsonApi::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- FunWithJsonApi::Exception
- Defined in:
- lib/fun_with_json_api/exception.rb
Direct Known Subclasses
FunWithJsonApi::Exceptions::IllegalClientGeneratedIdentifier, FunWithJsonApi::Exceptions::InvalidAttribute, FunWithJsonApi::Exceptions::InvalidClientGeneratedIdentifier, FunWithJsonApi::Exceptions::InvalidDocument, FunWithJsonApi::Exceptions::InvalidDocumentIdentifier, FunWithJsonApi::Exceptions::InvalidDocumentType, FunWithJsonApi::Exceptions::InvalidRelationship, FunWithJsonApi::Exceptions::InvalidRelationshipType, FunWithJsonApi::Exceptions::MissingRelationship, FunWithJsonApi::Exceptions::MissingResource, FunWithJsonApi::Exceptions::RelationshipMethodNotSupported, FunWithJsonApi::Exceptions::UnauthorizedAttribute, FunWithJsonApi::Exceptions::UnauthorizedRelationship, FunWithJsonApi::Exceptions::UnauthorizedResource, FunWithJsonApi::Exceptions::UnknownAttribute, FunWithJsonApi::Exceptions::UnknownRelationship
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
-
#http_status ⇒ Integer
The http status code for rendering this error.
-
#initialize(message, payload) ⇒ Exception
constructor
A new instance of Exception.
Constructor Details
#initialize(message, payload) ⇒ Exception
Returns a new instance of Exception.
7 8 9 10 |
# File 'lib/fun_with_json_api/exception.rb', line 7 def initialize(, payload) super() @payload = Array.wrap(payload) end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/fun_with_json_api/exception.rb', line 5 def payload @payload end |
Instance Method Details
#http_status ⇒ Integer
Returns The http status code for rendering this error.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fun_with_json_api/exception.rb', line 13 def http_status payload_statuses = payload.map(&:status).uniq if payload_statuses.length == 1 Integer(payload_statuses.first || '400') # Return the unique status code elsif payload_statuses.any? { |status| status.starts_with?('5') } 500 # We have a server error else 400 # Bad Request end end |