Sha256: d2b9764374218c48cd77c915c746d75d8c179e280d1a76464a3c2d73169b9987

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module Faraday
  class Response::RainmakerErrors < Response::Middleware
      def on_complete(env)
	   case env[:status]
			when 400
			raise Rainmaker::BadRequest.new(error_message(env), env[:response_headers])
		  when 401
			raise Rainmaker::Unauthorized.new(error_message(env), env[:response_headers])
		  when 403
			raise Rainmaker::Forbidden.new(error_message(env), env[:response_headers])
		  when 404
			raise Rainmaker::NotFound.new(error_message(env), env[:response_headers])
		  when 422
			raise Rainmaker::Invalid.new(error_message(env), env[:response_headers])
 		when 500
        raise Rainmaker::InternalServerError.new(error_message(env), env[:response_headers])
      when 502
        raise Rainmaker::BadGateway.new(error_message(env), env[:response_headers])
      when 503
        raise Rainmaker::ServiceUnavailable.new(error_message(env), env[:response_headers])
      end
		   end

	 def error_message(env)
      "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}"
    end

    def initialize(app)
      super
      @parser = nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rainmaker-0.1.4 lib/faraday/response/rainmaker_errors.rb
rainmaker-0.1.3 lib/faraday/response/rainmaker_errors.rb