Class: Pragma::Operation::Error
- Inherits:
-
Object
- Object
- Pragma::Operation::Error
- Defined in:
- lib/pragma/operation/error.rb
Overview
A generic error entity to hold error information for HTTP responses.
This format is not mandatory, but recommended for consistency and convenience.
Instance Attribute Summary collapse
-
#error_message ⇒ String
readonly
A human-readable error message.
-
#error_type ⇒ Symbol|String
readonly
A machine-readable error type.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Instance Method Summary collapse
-
#as_json ⇒ Hash
Converts the entity to a hash ready to be dumped as JSON.
-
#initialize(error_type:, error_message:, meta: {}) ⇒ Error
constructor
Creates a new error entity.
-
#to_json ⇒ String
Dumps the JSON representation as a JSON string.
Constructor Details
#initialize(error_type:, error_message:, meta: {}) ⇒ Error
Creates a new error entity.
24 25 26 27 28 |
# File 'lib/pragma/operation/error.rb', line 24 def initialize(error_type:, error_message:, meta: {}) @error_type = error_type @error_message = @meta = end |
Instance Attribute Details
#error_message ⇒ String (readonly)
Returns a human-readable error message.
17 |
# File 'lib/pragma/operation/error.rb', line 17 attr_reader :error_type, :error_message, :meta |
#error_type ⇒ Symbol|String (readonly)
Returns a machine-readable error type.
17 18 19 |
# File 'lib/pragma/operation/error.rb', line 17 def error_type @error_type end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
17 |
# File 'lib/pragma/operation/error.rb', line 17 attr_reader :error_type, :error_message, :meta |
Instance Method Details
#as_json ⇒ Hash
Converts the entity to a hash ready to be dumped as JSON.
33 34 35 36 37 38 39 |
# File 'lib/pragma/operation/error.rb', line 33 def as_json(*) { error_type: error_type, error_message: , meta: } end |
#to_json ⇒ String
Dumps the JSON representation as a JSON string.
46 47 48 |
# File 'lib/pragma/operation/error.rb', line 46 def to_json JSON.dump as_json end |