Sha256: d1776fc5ed2331dda323a5b720d4aa2a3af2f426c61d7d7790fd157e4c195205

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8

require 'faraday'
require 'github_api/error'

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

    def on_complete(env)
      case env[:status].to_i
      when 400
        raise Github::BadRequest.new(response_message(env), env[:response_headers])
      when 401
        raise Github::Unauthorised.new(response_message(env), env[:response_headers])
      when 403
        raise Github::Forbidden.new(response_message(env), env[:response_headers])
      when 404
        raise Github::ResourceNotFound.new(response_message(env), env[:response_headers])
      when 500
        raise Github::InternalServerError.new(response_message(env), env[:response_headers])
      when 503
        raise Github::ServiceUnavailable.new(response_message(env), env[:response_headers])
      when 400...600
        raise Github::Error.new(response_message(env), env[:response_headers])
      end
    end

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

  end # Response::RaiseError
end # Github

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
github_api-0.3.9 lib/github_api/response/raise_error.rb
github_api-0.3.8 lib/github_api/response/raise_error.rb
github_api-0.3.7 lib/github_api/response/raise_error.rb
github_api-0.3.6 lib/github_api/response/raise_error.rb
github_api-0.3.4 lib/github_api/response/raise_error.rb
github_api-0.3.3 lib/github_api/response/raise_error.rb
github_api-0.3.2 lib/github_api/response/raise_error.rb
github_api-0.3.1 lib/github_api/response/raise_error.rb
github_api-0.3.0 lib/github_api/response/raise_error.rb
github_api-0.2.2 lib/github_api/response/raise_error.rb
github_api-0.2.1 lib/github_api/response/raise_error.rb
github_api-0.2.0 lib/github_api/response/raise_error.rb
github_api-0.1.2 lib/github_api/response/raise_error.rb
github_api-0.1.1 lib/github_api/response/raise_error.rb
github_api-0.1.0 lib/github_api/response/raise_error.rb
github_api-0.1.0.pre lib/github_api/response/raise_error.rb