Sha256: a006e81ebebe53406d7b6dfef4ab80e30eb52373a2438fdb70a4fe2f2bbc9c8f

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "faraday"

module EveOnline
  module ESI
    module FaradayMiddlewares
      class RaiseErrors < Faraday::Middleware
        def call(env)
          @app.call(env).on_complete do |environment|
            on_complete(environment)
          end
        end

        def on_complete(env)
          case env[:status]
          when 204
            raise EveOnline::Exceptions::NoContent
          when 400
            raise EveOnline::Exceptions::BadRequest
          when 401
            raise EveOnline::Exceptions::Unauthorized
          when 403
            raise EveOnline::Exceptions::Forbidden
          when 404
            raise EveOnline::Exceptions::ResourceNotFound
          when 420
            raise EveOnline::Exceptions::ErrorLimited
          when 500
            raise EveOnline::Exceptions::InternalServerError
          when 502
            raise EveOnline::Exceptions::BadGateway
          when 503
            raise EveOnline::Exceptions::ServiceUnavailable
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
eve_online-0.46.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.45.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.44.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.43.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.42.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.41.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.40.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.39.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb
eve_online-0.38.0 lib/eve_online/esi/faraday_middlewares/raise_errors.rb