Sha256: bc54d253c8ded487ac7e2593bc704360d294b2377d56d0ebf68cdc20e34296d3

Contents?: true

Size: 771 Bytes

Versions: 2

Compression:

Stored size: 771 Bytes

Contents

require 'faraday'

module FaradayMiddleWare
  class RaiseFormi9HttpException < Faraday::Middleware
    def initialize(app)
      super(app)
    end

    def call(env)
      @app.call(env).on_complete do |response|
        case response.status.to_i
        when 400
          raise Formi9::BadRequest.new(response)
        when 401
          raise Formi9::Unauthorized.new(response)
        when 404
          raise Formi9::NotFound.new(response)
        when 500
          raise Formi9::InternalServerError.new(response)
        when 502
          raise Formi9::BadGateway.new(response)
        when 503
          raise Formi9::ServiceUnavailable.new(response)
        when 504
          raise Formi9::GatewayTimeout.new(response)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
formi9-0.1.8 lib/faraday/raise_formi9_http_exception.rb
formi9-0.1.7 lib/faraday/raise_formi9_http_exception.rb