Exception: Flinks::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Flinks::Error
- Defined in:
- lib/flinks/error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
Constructor Details
#initialize(response) ⇒ Flinks::Error
43 44 45 46 47 48 |
# File 'lib/flinks/error.rb', line 43 def initialize(response) @response = response @code = response.code super() end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/flinks/error.rb', line 3 def code @code end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/flinks/error.rb', line 3 def response @response end |
Class Method Details
.error_for_403(response) ⇒ Flinks::Error
33 34 35 36 37 38 39 |
# File 'lib/flinks/error.rb', line 33 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
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/flinks/error.rb', line 7 def self.from_response(response) klass = case response.code when 400 then Flinks::BadRequest 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 klass.new(response) end |
Instance Method Details
#build_message ⇒ String
51 52 53 54 55 56 |
# File 'lib/flinks/error.rb', line 51 def = response.parse['Message'] << " - FlinksCode: #{response.parse['FlinksCode']}" rescue HTTP::Error response.reason end |