提交 88fb3e12 编写于 作者: M Mislav Marohnić

better net/http exceptions handling

上级 96201897
...@@ -284,7 +284,7 @@ module Hub ...@@ -284,7 +284,7 @@ module Hub
args.after { puts "new remote: #{github_user}" } args.after { puts "new remote: #{github_user}" }
end end
end end
rescue Net::HTTPExceptions rescue HTTPExceptions
display_http_exception("creating fork", $!.response) display_http_exception("creating fork", $!.response)
exit 1 exit 1
end end
...@@ -331,7 +331,7 @@ module Hub ...@@ -331,7 +331,7 @@ module Hub
args.after { puts "#{action}: #{github_user}/#{repo_name}" } args.after { puts "#{action}: #{github_user}/#{repo_name}" }
end end
rescue Net::HTTPExceptions rescue HTTPExceptions
display_http_exception("creating repository", $!.response) display_http_exception("creating repository", $!.response)
exit 1 exit 1
end end
...@@ -767,6 +767,14 @@ help ...@@ -767,6 +767,14 @@ help
defined? ::OpenSSL defined? ::OpenSSL
end 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) def display_http_exception(action, response)
warn "Error #{action}: #{response.message} (HTTP #{response.code})" warn "Error #{action}: #{response.message} (HTTP #{response.code})"
warn "Check your token configuration (`git config github.token`)" if response.code.to_i == 401 warn "Check your token configuration (`git config github.token`)" if response.code.to_i == 401
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册