Exception: Yao::ServerError
- Inherits:
-
StandardError
- Object
- StandardError
- Yao::ServerError
- Defined in:
- lib/yao/error.rb
Direct Known Subclasses
BadMediaType, BadMethod, BadRequest, BuildInProgress, ComputeFault, Conflict, Forbidden, ItemNotFound, NetworkNotFound, NotFound, OverLimit, ServerCapacityUnavailable, ServiceUnavailable, Unauthorized, UnprocessableEntity
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, requested_env) ⇒ ServerError
constructor
A new instance of ServerError.
Constructor Details
#initialize(message, requested_env) ⇒ ServerError
Returns a new instance of ServerError.
6 7 8 9 10 |
# File 'lib/yao/error.rb', line 6 def initialize(, requested_env) @status = requested_env.status @env = requested_env super() end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
11 12 13 |
# File 'lib/yao/error.rb', line 11 def env @env end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/yao/error.rb', line 11 def status @status end |
Class Method Details
.detect(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yao/error.rb', line 13 def self.detect(env) case env.status when 400 if env.body && env.body["computeFault"] ComputeFault.new((env.body), env) elsif env.body && env.body.to_a.join.include?('NetworkNotFound') NetworkNotFound.new((env.body), env) else BadRequest.new((env.body), env) end when 401 Unauthorized.new((env.body), env) when 404 if env.body && env.body["itemNotFound"] ItemNotFound.new((env.body), env) else NotFound.new("The resource could not be found.", env) end when 405 BadMethod.new((env.body), env) when 409 if env.body && env.body["buildInProgress"] BuildInProgress.new((env.body), env) else Conflict.new((env.body), env) end when 413 OverLimit.new((env.body), env) when 415 BadMediaType.new((env.body), env) when 422 UnprocessableEntity.new((env.body), env) when 500 ComputeFault.new((env.body), env) when 503 if env.body && env.body[" serverCapacityUnavailable"] ServerCapacityUnavailable.new((env.body), env) else ServiceUnavailable.new((env.body), env) end else new((env.body), env) end rescue => e new("Detection failed - %s" % e., env) end |
.extract_message(body) ⇒ Object
60 61 62 63 64 |
# File 'lib/yao/error.rb', line 60 def self.(body) body.values.first["message"] or raise rescue "Something is wrong. - %s" % body.inspect end |