Exception: Flinks::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Flinks::Error
- Defined in:
- lib/flinks/error.rb
Direct Known Subclasses
ClientError, OperationDispatched, OperationPending, ServerError
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
- .build_message(response) ⇒ String
- .error_for_202(response) ⇒ Flinks::Error
- .error_for_400(response) ⇒ Flinks::Error
- .error_for_403(response) ⇒ Flinks::Error
- .from_response(response) ⇒ Flinks::Error
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/flinks/error.rb', line 5 def code @code end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/flinks/error.rb', line 5 def response @response end |
Class Method Details
.build_message(response) ⇒ String
70 71 72 73 74 75 |
# File 'lib/flinks/error.rb', line 70 def self.(response) = response.parse['Message'] << " - FlinksCode: #{response.parse['FlinksCode']}" rescue HTTP::Error response.reason end |
.error_for_202(response) ⇒ Flinks::Error
40 41 42 43 44 45 46 |
# File 'lib/flinks/error.rb', line 40 def self.error_for_202(response) if response.parse['FlinksCode'] == 'OPERATION_PENDING' Flinks::OperationPending else Flinks::OperationDispatched end end |
.error_for_400(response) ⇒ Flinks::Error
50 51 52 53 54 55 56 |
# File 'lib/flinks/error.rb', line 50 def self.error_for_400(response) if response.parse['FlinksCode'] == 'SESSION_NONEXISTENT' Flinks::SessionNonexistent else Flinks::BadRequest end end |
.error_for_403(response) ⇒ Flinks::Error
60 61 62 63 64 65 66 |
# File 'lib/flinks/error.rb', line 60 def self.error_for_403(response) if response.parse['FlinksCode'] == 'TOO_MANY_REQUESTS' Flinks::TooManyRequests else Flinks::Forbidden end end |
.from_response(response) ⇒ Flinks::Error
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/flinks/error.rb', line 9 def self.from_response(response) klass = case response.code when 202 then error_for_202(response) when 400 then error_for_400(response) when 401 then Flinks::Unauthorized when 403 then error_for_403(response) when 404 then Flinks::NotFound when 405 then Flinks::MethodNotAllowed when 406 then Flinks::NotAcceptable when 409 then Flinks::Conflict when 415 then Flinks::UnsupportedMediaType when 422 then Flinks::UnprocessableEntity when 400..499 then Flinks::ClientError when 500 then Flinks::InternalServerError when 501 then Flinks::NotImplemented when 502 then Flinks::BadGateway when 503 then Flinks::ServiceUnavailable when 500..599 then Flinks::ServerError else self end error = klass.new((response)) error.response = response error.code = response.code error end |