Sha256: 52dbf2c4e378c2a76fc5da3bfffdf89863805988e85bc8b66db8e2d19afb4cef
Contents?: true
Size: 1.2 KB
Versions: 6
Compression:
Stored size: 1.2 KB
Contents
require 'faraday' # @api private module Faraday class Response::RaiseError < Response::Middleware def self.register_on_complete(env) env[:response].on_complete do |response| case response[:status].to_i when 400 raise Octokit::BadRequest, error_message(response) when 401 raise Octokit::Unauthorized, error_message(response) when 403 raise Octokit::Forbidden, error_message(response) when 404 raise Octokit::NotFound, error_message(response) when 406 raise Octokit::NotAcceptable, error_message(response) when 500 raise Octokit::InternalServerError, error_message(response) when 501 raise Octokit::NotImplemented, error_message(response) when 502 raise Octokit::BadGateway, error_message(response) when 503 raise Octokit::ServiceUnavailable, error_message(response) end end end def initialize(app) super end private def self.error_message(response) "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{(': ' + response[:body]) if response[:body]}" end end end
Version data entries
6 entries across 6 versions & 1 rubygems