Exception: ForgetPasswords::ErrorResponse
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- ForgetPasswords::ErrorResponse
- Defined in:
- lib/forget-passwords.rb
Overview
An error response (with status, headers, etc) that can be raised and caught.
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.exception(message) ⇒ ForgetPasswords::ErrorResponse
Generate a new exception with a Rack::Response as a message.
Instance Method Summary collapse
-
#exception(message = nil) ⇒ ForgetPasswords::ErrorResponse
Returns itself if the message is nil.
-
#initialize(body = nil, status = 500, headers = {}) ⇒ ErrorResponse
constructor
Create a new error response.
-
#message ⇒ String
Returns the error message (which is the response body).
-
#message=(msg) ⇒ Object
Sets a new error message (response body).
Constructor Details
#initialize(body = nil, status = 500, headers = {}) ⇒ ErrorResponse
Create a new error response.
31 32 33 34 35 36 37 |
# File 'lib/forget-passwords.rb', line 31 def initialize body = nil, status = 500, headers = {} if body.is_a? Rack::Response @response = body else @response = Rack::Response.new body, status, headers end end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
23 24 25 |
# File 'lib/forget-passwords.rb', line 23 def response @response end |
Class Method Details
.exception(message) ⇒ ForgetPasswords::ErrorResponse
Generate a new exception with a Rack::Response as a message. Otherwise creates a new error response.
63 64 65 66 67 68 69 70 |
# File 'lib/forget-passwords.rb', line 63 def self.exception # XXX TODO auto generate (x)html from text message? case when Rack::Response then self.new else self.new .to_s, 500, { 'Content-Type' => 'text/plain' } end end |
Instance Method Details
#exception(message = nil) ⇒ ForgetPasswords::ErrorResponse
Returns itself if the message is nil. Otherwise it runs the class method with the message as its argument.
80 81 82 83 |
# File 'lib/forget-passwords.rb', line 80 def exception = nil return self if .nil? self.class.exception end |
#message ⇒ String
Returns the error message (which is the response body).
43 44 45 |
# File 'lib/forget-passwords.rb', line 43 def @response.body end |
#message=(msg) ⇒ Object
Sets a new error message (response body). Does not change anything else, like headers or status or anything.
52 53 54 |
# File 'lib/forget-passwords.rb', line 52 def msg @response.body = msg.to_s end |