excon 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of excon might be problematic. Click here for more details.

@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'excon'
16
- s.version = '0.2.6'
17
- s.date = '2010-11-29'
16
+ s.version = '0.2.7'
17
+ s.date = '2010-11-30'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -13,7 +13,7 @@ require 'excon/response'
13
13
  module Excon
14
14
 
15
15
  unless const_defined?(:VERSION)
16
- VERSION = '0.2.6'
16
+ VERSION = '0.2.7'
17
17
  end
18
18
 
19
19
  unless const_defined?(:CHUNK_SIZE)
@@ -102,7 +102,7 @@ module Excon
102
102
  response
103
103
  rescue => socket_error
104
104
  reset
105
- raise(socket_error)
105
+ raise(Excon::Errors::SocketError.new(socket_error))
106
106
  end
107
107
 
108
108
  if params[:expects] && ![*params[:expects]].include?(response.status)
@@ -114,7 +114,8 @@ module Excon
114
114
 
115
115
  rescue => request_error
116
116
  if params[:idempotent] &&
117
- (!request_error.is_a?(Excon::Errors::Error) || response.status != 404)
117
+ (request_error.is_a?(Excon::Errors::SocketError) ||
118
+ (request_error.is_a?(Excon::Errors::HTTPStatusError) && response.status != 404))
118
119
  retries_remaining ||= 4
119
120
  retries_remaining -= 1
120
121
  if retries_remaining > 0
@@ -1,7 +1,18 @@
1
1
  module Excon
2
-
3
2
  module Errors
4
- class Error < StandardError
3
+
4
+ class Error < StandardError; end
5
+
6
+ class SocketError < Error
7
+ attr_reader :socket_error
8
+
9
+ def initialize(socket_error=nil)
10
+ super(socket_error.message)
11
+ @socket_error = socket_error
12
+ end
13
+ end
14
+
15
+ class HTTPStatusError < Error
5
16
  attr_reader :request, :response
6
17
 
7
18
  def initialize(msg, request = nil, response = nil)
@@ -11,46 +22,46 @@ module Excon
11
22
  end
12
23
  end
13
24
 
14
- class Continue < Error; end # 100
15
- class SwitchingProtocols < Error; end # 101
16
- class OK < Error; end # 200
17
- class Created < Error; end # 201
18
- class Accepted < Error; end # 202
19
- class NonAuthoritativeInformation < Error; end # 203
20
- class NoContent < Error; end # 204
21
- class ResetContent < Error; end # 205
22
- class PartialContent < Error; end # 206
23
- class MultipleChoices < Error; end # 300
24
- class MovedPermanently < Error; end # 301
25
- class Found < Error; end # 302
26
- class SeeOther < Error; end # 303
27
- class NotModified < Error; end # 304
28
- class UseProxy < Error; end # 305
29
- class TemporaryRedirect < Error; end # 307
30
- class BadRequest < Error; end # 400
31
- class Unauthorized < Error; end # 401
32
- class PaymentRequired < Error; end # 402
33
- class Forbidden < Error; end # 403
34
- class NotFound < Error; end # 404
35
- class MethodNotAllowed < Error; end # 405
36
- class NotAcceptable < Error; end # 406
37
- class ProxyAuthenticationRequired < Error; end # 407
38
- class RequestTimeout < Error; end # 408
39
- class Conflict < Error; end # 409
40
- class Gone < Error; end # 410
41
- class LengthRequired < Error; end # 411
42
- class PreconditionFailed < Error; end # 412
43
- class RequestEntityTooLarge < Error; end # 412
44
- class RequestURITooLong < Error; end # 414
45
- class UnsupportedMediaType < Error; end # 415
46
- class RequestedRangeNotSatisfiable < Error; end # 416
47
- class ExpectationFailed < Error; end # 417
48
- class UnprocessableEntity < Error; end # 422
49
- class InternalServerError < Error; end # 500
50
- class NotImplemented < Error; end # 501
51
- class BadGateway < Error; end # 502
52
- class ServiceUnavailable < Error; end # 503
53
- class GatewayTimeout < Error; end # 504
25
+ class Continue < HTTPStatusError; end # 100
26
+ class SwitchingProtocols < HTTPStatusError; end # 101
27
+ class OK < HTTPStatusError; end # 200
28
+ class Created < HTTPStatusError; end # 201
29
+ class Accepted < HTTPStatusError; end # 202
30
+ class NonAuthoritativeInformation < HTTPStatusError; end # 203
31
+ class NoContent < HTTPStatusError; end # 204
32
+ class ResetContent < HTTPStatusError; end # 205
33
+ class PartialContent < HTTPStatusError; end # 206
34
+ class MultipleChoices < HTTPStatusError; end # 300
35
+ class MovedPermanently < HTTPStatusError; end # 301
36
+ class Found < HTTPStatusError; end # 302
37
+ class SeeOther < HTTPStatusError; end # 303
38
+ class NotModified < HTTPStatusError; end # 304
39
+ class UseProxy < HTTPStatusError; end # 305
40
+ class TemporaryRedirect < HTTPStatusError; end # 307
41
+ class BadRequest < HTTPStatusError; end # 400
42
+ class Unauthorized < HTTPStatusError; end # 401
43
+ class PaymentRequired < HTTPStatusError; end # 402
44
+ class Forbidden < HTTPStatusError; end # 403
45
+ class NotFound < HTTPStatusError; end # 404
46
+ class MethodNotAllowed < HTTPStatusError; end # 405
47
+ class NotAcceptable < HTTPStatusError; end # 406
48
+ class ProxyAuthenticationRequired < HTTPStatusError; end # 407
49
+ class RequestTimeout < HTTPStatusError; end # 408
50
+ class Conflict < HTTPStatusError; end # 409
51
+ class Gone < HTTPStatusError; end # 410
52
+ class LengthRequired < HTTPStatusError; end # 411
53
+ class PreconditionFailed < HTTPStatusError; end # 412
54
+ class RequestEntityTooLarge < HTTPStatusError; end # 412
55
+ class RequestURITooLong < HTTPStatusError; end # 414
56
+ class UnsupportedMediaType < HTTPStatusError; end # 415
57
+ class RequestedRangeNotSatisfiable < HTTPStatusError; end # 416
58
+ class ExpectationFailed < HTTPStatusError; end # 417
59
+ class UnprocessableEntity < HTTPStatusError; end # 422
60
+ class InternalServerError < HTTPStatusError; end # 500
61
+ class NotImplemented < HTTPStatusError; end # 501
62
+ class BadGateway < HTTPStatusError; end # 502
63
+ class ServiceUnavailable < HTTPStatusError; end # 503
64
+ class GatewayTimeout < HTTPStatusError; end # 504
54
65
 
55
66
  # Messages for nicer exceptions, from rfc2616
56
67
  def self.status_error(request, response)
@@ -96,7 +107,7 @@ module Excon
96
107
  503 => [Excon::Errors::ServiceUnavailable, 'Service Unavailable'],
97
108
  504 => [Excon::Errors::GatewayTimeout, 'Gateway Timeout']
98
109
  }
99
- error, message = @errors[response.status] || [Excon::Errors::Error, 'Unknown']
110
+ error, message = @errors[response.status] || [Excon::Errors::HTTPStatusError, 'Unknown']
100
111
  error.new("Expected(#{request[:expects].inspect}) <=> Actual(#{response.status} #{message})\n request => #{request.inspect}\n response => #{response.inspect}", request, response)
101
112
  end
102
113
 
@@ -20,7 +20,7 @@ module Excon
20
20
  end
21
21
  end
22
22
 
23
- unless params[:method] == 'HEAD'
23
+ unless params[:method].to_s.upcase == 'HEAD'
24
24
  if !block || (params[:expects] && ![*params[:expects]].include?(response.status))
25
25
  response.body = ''
26
26
  block = lambda { |chunk| response.body << chunk }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 6
9
- version: 0.2.6
8
+ - 7
9
+ version: 0.2.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - geemus (Wesley Beary)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-29 00:00:00 -08:00
17
+ date: 2010-11-30 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency