Exception: Passwordstate::HTTPError
- Inherits:
-
PasswordstateError
- Object
- RuntimeError
- PasswordstateError
- Passwordstate::HTTPError
- Defined in:
- lib/passwordstate/errors.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code, request, response, errors = []) ⇒ HTTPError
constructor
A new instance of HTTPError.
Constructor Details
#initialize(code, request, response, errors = []) ⇒ HTTPError
11 12 13 14 15 16 17 18 19 |
# File 'lib/passwordstate/errors.rb', line 11 def initialize(code, request, response, errors = []) @code = code.to_i @request = request @response = response @errors = errors errorstr = errors.map { |err| err['message'] || err['phrase'] || err['error'] }.join('; ') super "Passwordstate responded with an error to the request:\n#{errorstr}" end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
9 10 11 |
# File 'lib/passwordstate/errors.rb', line 9 def code @code end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/passwordstate/errors.rb', line 9 def errors @errors end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/passwordstate/errors.rb', line 9 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/passwordstate/errors.rb', line 9 def response @response end |
Class Method Details
.new_by_code(code, req, res, errors = []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/passwordstate/errors.rb', line 21 def self.new_by_code(code, req, res, errors = []) code_i = code.to_i errtype = nil errtype ||= if code_i == 401 errtype ||= ForbiddenError if code_i == 403 errtype ||= NotFoundError if code_i == 404 errtype ||= ClientError if code_i >= 400 && code_i < 500 errtype ||= ServerError if code_i >= 500 && code_i < 600 if code_i == 302 && res['location'].start_with?('/error/generalerror.aspx?') errtype ||= ServerError errors = [{ 'phrase' => 'Response code 302, most likely meaning an authorization error' }] end errtype ||= HTTPError errtype.new(code_i, req, res, errors) end |