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) ⇒ Boolean
-
.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.
47 48 49 50 |
# File 'lib/syntropy/errors.rb', line 47 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.
55 56 57 |
# File 'lib/syntropy/errors.rb', line 55 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) ⇒ Boolean
21 22 23 |
# File 'lib/syntropy/errors.rb', line 21 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
33 |
# File 'lib/syntropy/errors.rb', line 33 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
28 |
# File 'lib/syntropy/errors.rb', line 28 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
38 |
# File 'lib/syntropy/errors.rb', line 38 def self.teapot(msg = 'I\'m a teapot') = new(msg, Status::TEAPOT) |