diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-06-09 07:53:59 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-06-09 07:53:59 +0000 |
commit | fdd3d8551ffbb1a805b5cd559314ed4be7e1c03c (patch) | |
tree | cea1bdbed8b282192c55826328f1959ec3c81a7e /lib/net | |
parent | eb4c6c241d2032ac858c481b35de72dee28bad74 (diff) | |
download | ruby-fdd3d8551ffbb1a805b5cd559314ed4be7e1c03c.tar.gz |
o protocol.rb: ProtocolError can take data
o http.rb: raise exception with response
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net')
-rw-r--r-- | lib/net/http.rb | 18 | ||||
-rw-r--r-- | lib/net/protocol.rb | 17 |
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb index dfc776e9f3..40025d06a5 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -54,6 +54,20 @@ module Net If called as iterator, give a part String of entity body. + Note: + If status is not 2xx(success), ProtocolError exception is + raised. At that time, you can get Response object from + execption object. (same in head/post) + + ex. + + begin + head, body = http.get(...) + rescue ProtoRetriableError + response = $!.data + ... + end + : head( path, header = nil ) get only header from "path" on connecting host. "header" is a Hash like { 'Accept' => '*/*', ... }. @@ -375,7 +389,9 @@ All "key" is case-insensitive. end def value - error! unless SuccessCode === self + unless SuccessCode === self then + error! self + end end end diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 02a469cc0d..01b659f72f 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -68,7 +68,7 @@ Object class Protocol - Version = '1.1.20' + Version = '1.1.21' class << self @@ -295,8 +295,8 @@ Object attr_reader :code_type, :code, :message alias msg message - def error! - raise @code_type.error_type, @code + ' ' + Net.quote(@message) + def error!( data = nil ) + raise code_type.error_type.new( code + ' ' + Net.quote(msg), data ) end end @@ -312,6 +312,17 @@ Object class ProtoRetriableError < ProtocolError; end ProtocRetryError = ProtoRetriableError + class ProtocolError + + def initialize( msg, data ) + super msg + @data = data + end + + attr :data + + end + class Code |