Sha256: 76b3ba0f864fcdf2331e98b909fd8ebc2722980dcdefc1360c0d91484023711a

Contents?: true

Size: 741 Bytes

Versions: 3

Compression:

Stored size: 741 Bytes

Contents

require 'faraday'
require 'footrest/http_error'

module Faraday
  class Response::RaiseFootrestHttpError < Response::Middleware
    ERROR_MAP = {
      400 => Footrest::HttpError::BadRequest,
      401 => Footrest::HttpError::Unauthorized,
      403 => Footrest::HttpError::Forbidden,
      404 => Footrest::HttpError::NotFound,
      405 => Footrest::HttpError::MethodNotAllowed,
      500 => Footrest::HttpError::InternalServerError,
      501 => Footrest::HttpError::NotImplemented,
      502 => Footrest::HttpError::BadGateway,
      503 => Footrest::HttpError::ServiceUnavailable
    }

    def on_complete(response)
      key = response[:status].to_i
      raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
footrest-0.2.0 lib/faraday/response/raise_footrest_http_error.rb
footrest-0.1.3 lib/faraday/response/raise_footrest_http_error.rb
footrest-0.1.2 lib/faraday/response/raise_footrest_http_error.rb