Exception: Ghost::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Ghost::Error
- Defined in:
- lib/ghost/errors.rb
Direct Known Subclasses
AuthenticationError, BadRequestError, ForbiddenError, NotFoundError, ServerError, UnprocessableError
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#error_type ⇒ Object
readonly
Returns the value of attribute error_type.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message = nil, error_type: nil, context: nil, status_code: nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(message = nil, error_type: nil, context: nil, status_code: nil) ⇒ Error
Returns a new instance of Error.
7 8 9 10 11 12 |
# File 'lib/ghost/errors.rb', line 7 def initialize( = nil, error_type: nil, context: nil, status_code: nil) @error_type = error_type @context = context @status_code = status_code super() end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/ghost/errors.rb', line 5 def context @context end |
#error_type ⇒ Object (readonly)
Returns the value of attribute error_type.
5 6 7 |
# File 'lib/ghost/errors.rb', line 5 def error_type @error_type end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
5 6 7 |
# File 'lib/ghost/errors.rb', line 5 def status_code @status_code end |
Class Method Details
.from_response(status, body) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ghost/errors.rb', line 14 def self.from_response(status, body) error_class = ERROR_MAP[status] || Error errors = body.is_a?(Hash) && body["errors"] ? body["errors"] : [] if errors.any? err = errors.first error_class.new( err["message"], error_type: err["type"], context: err["context"], status_code: status ) else error_class.new("Unknown error", status_code: status) end end |