Sha256: b48fe66ba65b4a3328e090598d1dd07cf35e51a2abfe42df48efd12f30ade5fd
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 KB
Contents
module SearchSpring module Errors class SearchSpringError < ::StandardError; end class NotFound < SearchSpringError; end class UnprocessableEntity < SearchSpringError; end class InternalServerError < SearchSpringError; end class NotAuthorized < SearchSpringError; end class AuthenticationError < SearchSpringError; end class RequestError < Faraday::Response::Middleware def on_complete(env) # Ignore any non-error response codes return if (status = env[:status]) < 400 case status when 404 raise Errors::NotFound, response_values(env) when 422 raise Errors::UnprocessableEntity, response_values(env) when 401 raise Errors::NotAuthorized, response_values(env) when 407 # mimic the behavior that we get with proxy requests with HTTPS raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "} when 408...600 raise Errors::InternalServerError, response_values(env) # Treat any other errors as 500 end end def response_values(env) { status: env.status, headers: env.response_headers, body: env.body } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
search_spring-0.2.1 | lib/search_spring/errors.rb |