From 88fb3e12ea4dbf241c81c383c8efe082b7994428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Wed, 19 Oct 2011 14:40:38 +0200 Subject: [PATCH] better net/http exceptions handling --- lib/hub/commands.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index b16281bf..778661ed 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -284,7 +284,7 @@ module Hub args.after { puts "new remote: #{github_user}" } end end - rescue Net::HTTPExceptions + rescue HTTPExceptions display_http_exception("creating fork", $!.response) exit 1 end @@ -331,7 +331,7 @@ module Hub args.after { puts "#{action}: #{github_user}/#{repo_name}" } end - rescue Net::HTTPExceptions + rescue HTTPExceptions display_http_exception("creating repository", $!.response) exit 1 end @@ -767,6 +767,14 @@ help defined? ::OpenSSL end + # Fake exception type for net/http exception handling. + # Necessary because net/http may or may not be loaded at the time. + module HTTPExceptions + def self.===(exception) + exception.class.ancestors.map {|a| a.to_s }.include? 'Net::HTTPExceptions' + end + end + def display_http_exception(action, response) warn "Error #{action}: #{response.message} (HTTP #{response.code})" warn "Check your token configuration (`git config github.token`)" if response.code.to_i == 401 -- GitLab