Class: Easy::Api::Error
- Inherits:
-
Object
- Object
- Easy::Api::Error
- Defined in:
- lib/easy/api/error.rb
Overview
Encapsulates the types of errors that API calls can respond with
Constant Summary collapse
- CODES =
{ invalid: 400, unauthorized: 401, not_found: 404, unexpected: 500 }
- MESSAGES =
{ invalid: "Invalid request", unauthorized: "This request requires a valid Private API Key", not_found: "Resource not found", unexpected: 'Sorry! An exception has occured. Please try again later', }
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Hash
Used by Rails to parse the error as json.
-
#initialize(type, msg = nil) ⇒ Error
constructor
Initializes a new error based on the type, with an optional custom message.
-
#to_hash ⇒ Hash
Returns the error as a hash.
Constructor Details
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/easy/api/error.rb', line 4 def code @code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/easy/api/error.rb', line 4 def @message end |
Instance Method Details
#as_json(options = {}) ⇒ Hash
Used by Rails to parse the error as json
39 40 41 |
# File 'lib/easy/api/error.rb', line 39 def as_json(={}) to_hash end |
#to_hash ⇒ Hash
Returns the error as a hash
32 33 34 |
# File 'lib/easy/api/error.rb', line 32 def to_hash {:code => @code, :message => @message} end |