100% free for Open Source, forever. Get another set of eyes on your code.

Take a look. Our new design is currently in beta, but you can start using it today!

A
 

Echowrap::Response

Updated more than 3 months ago.

No issues here.

Congrats! Give yourself time to reflect on your awesome coding skillz.

require 'faraday'
require 'echowrap/error/bad_gateway'
require 'echowrap/error/bad_request'
require 'echowrap/error/forbidden'
require 'echowrap/error/gateway_timeout'
require 'echowrap/error/internal_server_error'
require 'echowrap/error/not_acceptable'
require 'echowrap/error/not_found'
require 'echowrap/error/service_unavailable'
require 'echowrap/error/too_many_requests'
require 'echowrap/error/unauthorized'
require 'echowrap/error/unprocessable_entity'

module Echowrap
  module Response
    class RaiseError < Faraday::Response::Middleware

      def on_complete(env)
        status_code = env[:status].to_i
        error_class = @klass.errors[status_code]
        raise error_class.from_response(env) if error_class
      end

      def initialize(app, klass)
        @klass = klass
        super(app)
      end

    end
  end
end
0
Complexity
0
Duplication
31
Lines
0
Methods
N/A
Complexity / M
0
Churn
27
Lines of Code
N/A
LOC / Method