From: Minero Aoki Date: 2002-03-10T13:19:37+09:00 Subject: Re: net/http; 302 Hi, In mail "Re: net/http; 302" Tobias Reif wrote: > > rescue Net::HTTPMovedPermanently, Net::HTTPMovedTemporarily => detail > Thanks for your explanation, but the rescue line gives > > /cygdrive/c/RUBY/lib/ruby/1.6/net/protocol.rb:32:in `connect': class or > module required for rescue clause (TypeError) Sorry. This type of confusion is caused by my fault. net/http features are very complex. At first, Net::HTTP* is NOT a class in ruby 1.6. In 1.7 it is a class, but it is not an Exception, because Net::HTTP* are response classes. You can use response classes for case statement/=== comparison. You can use exception classes for rescue clause. Exception classes are: Net::ProtocolError > Net::ProtoRetriableError raised on 3xx Net::ProtoFatalError raised on 4xx Net::ProtoServerError raised on 5xx Response classes are: Net::HTTPResponse > 100 HTTPContinue 101 HTTPSwitchProtocol 200 HTTPOK 201 HTTPCreated 202 HTTPAccepted 203 HTTPNonAuthoritativeInformation 204 HTTPNoContent 205 HTTPResetContent 206 HTTPPartialContent 300 HTTPMultipleChoice 301 HTTPMovedPermanently 302 HTTPMovedTemporarily 304 HTTPNotModified 305 HTTPUseProxy 400 HTTPBadRequest 401 HTTPUnauthorized 402 HTTPPaymentRequired 403 HTTPForbidden 404 HTTPNotFound 405 HTTPMethodNotAllowed 406 HTTPNotAcceptable 407 HTTPProxyAuthenticationRequired 408 HTTPRequestTimeOut 409 HTTPConflict 410 HTTPGone 411 HTTPLengthRequired 412 HTTPPreconditionFailed 413 HTTPRequestEntityTooLarge 414 HTTPRequestURITooLarge 415 HTTPUnsupportedMediaType 500 HTTPNotImplemented 500 HTTPBadGateway 500 HTTPServiceUnavailable 500 HTTPGatewayTimeOut 500 HTTPVersionNotSupported I'll add this description to the document soon. -------------------------------------- Or, you can suppress all exceptions by calling Net::HTTP.version_1_2: require 'net/http' Net::HTTP.version_1_2 Net::HTTP.start(host, port) {|http| case res = http.get(path) when Net::HTTPMovedPermanently, Net::HTTPMovedTemporarily .... end } I highly recommend calling version_1_2 and forgot all miss-features of v1.1. I've prepared Net::HTTP.version_1_1 for only compatibility. So if you begin to write new scripts, use v1.2. net v1.2 is more clearer than v1.1. -- Minero Aoki