Exception: Syntropy::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Syntropy::Error
- Defined in:
- lib/syntropy/errors.rb
Overview
The base Syntropy error class
Direct Known Subclasses
Constant Summary collapse
- Status =
Qeweney::Status
- DEFAULT_STATUS =
By default, the HTTP status for errors is 500 Internal Server Error.
Status::INTERNAL_SERVER_ERROR
Instance Attribute Summary collapse
-
#http_status ⇒ Integer, String
readonly
Returns the HTTP status for the error.
Class Method Summary collapse
-
.http_status(err) ⇒ Integer, String
Returns the HTTP status for the given exception.
-
.log_error?(err) ⇒ bool
Returns true if the error should be logged.
-
.method_not_allowed(msg = 'Method not allowed') ⇒ Syntropy::Error
Creates an error with status 405 Method Not Allowed.
-
.not_found(msg = 'Not found') ⇒ Syntropy::Error
Creates an error with status 404 Not Found.
-
.teapot(msg = 'I\'m a teapot') ⇒ Syntropy::Error
Creates an error with status 418 I’m a teapot.
Instance Method Summary collapse
-
#initialize(msg = 'Internal server error', http_status = DEFAULT_STATUS) ⇒ void
constructor
Initializes a Syntropy error with the given HTTP status and message.
Constructor Details
#initialize(msg = 'Internal server error', http_status = DEFAULT_STATUS) ⇒ void
Initializes a Syntropy error with the given HTTP status and message.
55 56 57 58 |
# File 'lib/syntropy/errors.rb', line 55 def initialize(msg = 'Internal server error', http_status = DEFAULT_STATUS) super(msg) @http_status = http_status end |
Instance Attribute Details
#http_status ⇒ Integer, String (readonly)
Returns the HTTP status for the error.
63 64 65 |
# File 'lib/syntropy/errors.rb', line 63 def http_status @http_status end |
Class Method Details
.http_status(err) ⇒ Integer, String
Returns the HTTP status for the given exception.
17 18 19 |
# File 'lib/syntropy/errors.rb', line 17 def self.http_status(err) err.respond_to?(:http_status) ? err.http_status : DEFAULT_STATUS end |
.log_error?(err) ⇒ bool
Returns true if the error should be logged. Currently all errors are logged except for NOT FOUND errors.
26 27 28 |
# File 'lib/syntropy/errors.rb', line 26 def self.log_error?(err) http_status(err) != Status::NOT_FOUND end |
.method_not_allowed(msg = 'Method not allowed') ⇒ Syntropy::Error
Creates an error with status 405 Method Not Allowed.
40 |
# File 'lib/syntropy/errors.rb', line 40 def self.method_not_allowed(msg = 'Method not allowed') = new(msg, Status::METHOD_NOT_ALLOWED) |
.not_found(msg = 'Not found') ⇒ Syntropy::Error
Creates an error with status 404 Not Found.
34 |
# File 'lib/syntropy/errors.rb', line 34 def self.not_found(msg = 'Not found') = new(msg, Status::NOT_FOUND) |
.teapot(msg = 'I\'m a teapot') ⇒ Syntropy::Error
Creates an error with status 418 I’m a teapot.
46 |
# File 'lib/syntropy/errors.rb', line 46 def self.teapot(msg = 'I\'m a teapot') = new(msg, Status::TEAPOT) |