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
- DEFAULT_STATUS =
By default, the HTTP status for errors is 500 Internal Server Error.
HTTP::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.
53 54 55 56 |
# File 'lib/syntropy/errors.rb', line 53 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.
61 62 63 |
# File 'lib/syntropy/errors.rb', line 61 def http_status @http_status end |
Class Method Details
.http_status(err) ⇒ Integer, String
Returns the HTTP status for the given exception.
15 16 17 |
# File 'lib/syntropy/errors.rb', line 15 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.
24 25 26 |
# File 'lib/syntropy/errors.rb', line 24 def self.log_error?(err) http_status(err) != HTTP::NOT_FOUND end |
.method_not_allowed(msg = 'Method not allowed') ⇒ Syntropy::Error
Creates an error with status 405 Method Not Allowed.
38 |
# File 'lib/syntropy/errors.rb', line 38 def self.method_not_allowed(msg = 'Method not allowed') = new(msg, HTTP::METHOD_NOT_ALLOWED) |
.not_found(msg = 'Not found') ⇒ Syntropy::Error
Creates an error with status 404 Not Found.
32 |
# File 'lib/syntropy/errors.rb', line 32 def self.not_found(msg = 'Not found') = new(msg, HTTP::NOT_FOUND) |
.teapot(msg = 'I\'m a teapot') ⇒ Syntropy::Error
Creates an error with status 418 I’m a teapot.
44 |
# File 'lib/syntropy/errors.rb', line 44 def self.teapot(msg = 'I\'m a teapot') = new(msg, HTTP::TEAPOT) |