Sha256: bfdd14976ebbaa864e8a74f8876aa0627bd272656400714761a362839ffe87f4

Contents?: true

Size: 1.1 KB

Versions: 26

Compression:

Stored size: 1.1 KB

Contents

require 'faraday'

module Faraday

  class EdsExceptionMiddleware < Faraday::Middleware

  def initialize(app)
      super app
    end

    def call(env)
      @app.call(env).on_complete do |response|
        case response.status
          when 200
          when 400
            raise EBSCO::EDS::BadRequest.new(error_message(response))
          # when 401
          #   raise EBSCO::EDS::Unauthorized.new
          # when 403
          #   raise EBSCO::EDS::Forbidden.new
          # when 404
          #   raise EBSCO::EDS::NotFound.new
          # when 429
          #   raise EBSCO::EDS::TooManyRequests.new
          # when 500
          #   raise EBSCO::EDS::InternalServerError.new
          # when 503
          #   raise EBSCO::EDS::ServiceUnavailable.new
          else
            raise EBSCO::EDS::BadRequest.new(error_message(response))
        end
      end
    end

    private

    def error_message(response)
      #puts response.inspect
      {
          method: response.method,
          url: response.url,
          status: response.status,
          error_body: response.body
      }
    end

  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ebsco-eds-0.3.5.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.3.6.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.3.4.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.3.3.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.3.2.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.3.1.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.3.0.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.9.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.8.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.7.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.5.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.6.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.4.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.3.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.2.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.1.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.2.0.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.1.9.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.1.8.pre lib/faraday/eds_exception_middleware.rb
ebsco-eds-0.1.7.pre lib/faraday/eds_exception_middleware.rb