Exception: LayerVault::Response::Error
- Inherits:
-
StandardError
- Object
- StandardError
- LayerVault::Response::Error
- Defined in:
- lib/layervault/response/error.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
27 28 29 30 |
# File 'lib/layervault/response/error.rb', line 27 def initialize(response=nil) @response = response super() end |
Class Method Details
.from_response(response) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/layervault/response/error.rb', line 5 def self.from_response(response) status = response[:status].to_i body = response[:body].to_s headers = response[:response_headers] if klass = case status when 400 then LayerVault::Response::BadRequest when 401 then LayerVault::Response::Unauthorized when 403 then LayerVault::Response::Forbidden when 404 then LayerVault::Response::NotFound when 406 then LayerVault::Response::NotAcceptable when 400..499 then LayerVault::Response::ClientError when 500 then LayerVault::Response::InternalServerError when 501 then LayerVault::Response::NotImplemented when 502 then LayerVault::Response::BadGateway when 503 then LayerVault::Response::ServiceUnavailable when 500..599 then LayerVault::Response::ServerError end klass.new(response) end end |
Instance Method Details
#errors ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/layervault/response/error.rb', line 32 def errors if data && data.is_a?(Hash) data[:errors] || [] else [] end end |