Exception: Crowdkit::ServiceError
- Defined in:
- lib/crowdkit/error.rb
Overview
Custom error class for rescuing from all CrowdFlower errors
Direct Known Subclasses
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.from_response(response) ⇒ Crowdkit::Error
Returns the appropriate Crowdkit::Error sublcass based on status and response message.
Instance Method Summary collapse
-
#documentation_url ⇒ String
Documentation URL returned by the API for some errors.
-
#errors ⇒ Array<Hash>
Array of validation errors.
-
#initialize(response = nil) ⇒ ServiceError
constructor
A new instance of ServiceError.
Constructor Details
#initialize(response = nil) ⇒ ServiceError
Returns a new instance of ServiceError.
91 92 93 94 |
# File 'lib/crowdkit/error.rb', line 91 def initialize(response=nil) @response = Faraday::Response.new(response) super() end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
58 59 60 |
# File 'lib/crowdkit/error.rb', line 58 def response @response end |
Class Method Details
.from_response(response) ⇒ Crowdkit::Error
Returns the appropriate Crowdkit::Error sublcass based on status and response message
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/crowdkit/error.rb', line 65 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 Crowdkit::BadRequest when 401 then Crowdkit::Unauthorized when 403 then Crowdkit::Forbidden when 404 then Crowdkit::NotFound when 406 then Crowdkit::NotAcceptable when 409 then Crowdkit::Conflict when 415 then Crowdkit::UnsupportedMediaType when 422 then Crowdkit::UnprocessableEntity when 429 then Crowdkit::TooManyRequests when 400..499 then Crowdkit::ClientError when 500 then Crowdkit::InternalServerError when 501 then Crowdkit::NotImplemented when 502 then Crowdkit::BadGateway when 503 then Crowdkit::ServiceUnavailable when 500..599 then Crowdkit::ServerError end klass.new(response) end end |
Instance Method Details
#documentation_url ⇒ String
Documentation URL returned by the API for some errors
99 100 101 |
# File 'lib/crowdkit/error.rb', line 99 def documentation_url data[:_links][:documentation] if data.is_a?(Hash) && data[:_links] end |