faraday-raise-errors 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 773fb7c5a1d23e615652cb8e134d7ed5fe8fb91b
4
- data.tar.gz: 32c70ccbce201d376c895c37e2efa6325a86207b
3
+ metadata.gz: 554808c59e62112a3a83a942357124114c170430
4
+ data.tar.gz: b3f3c51e58434ebd59993183b194e795ec350989
5
5
  SHA512:
6
- metadata.gz: ae48c3207eb6470f998804fcceacd6c222f609cc89d2d2742ca7bc004d8d1d079347152579ee83d4a3470c656723b4372069ddce328d4b016dec2a6903b96904
7
- data.tar.gz: 801377761e6b606b0261d13b06ab03c0520cb1325f394c9528d1e358a7ae13b56bf18dcef16c8c14a75e2d29f7137fa7d9369fa604de28646bebb5032a3875b0
6
+ metadata.gz: 252ba4f63fba7856c824f3e57489a60061e834984b061b75a0d75e444ffa59d873ad8c77631f6408b7f0cfc8bd0738d09d219dc8975c4b9ec16c022619736f68
7
+ data.tar.gz: 711c0fbf45d46d09be81862fcad72ef4f5afa75c4455ce23320b6b1f7c8fc6a676431ddb311793cb42e34d96b5d6cbbe440f781d47eb839c0478180baa12f817
@@ -2,48 +2,82 @@ module Faraday
2
2
  module HTTP
3
3
  class Error < RuntimeError
4
4
  attr_reader :env
5
-
5
+
6
6
  def initialize(env, message=nil)
7
7
  @env = env
8
8
  super message || default_message(env)
9
9
  end
10
-
10
+
11
11
  def default_message(env)
12
12
  "#{status} from #{env[:url].host}#{env[:url].path}"
13
13
  end
14
-
14
+
15
15
  def status
16
16
  env[:status]
17
17
  end
18
18
  end
19
-
19
+
20
20
  class ClientError < Error; end
21
21
  class ServerError < Error; end
22
22
  class UnrecognizedResponse < Error; end
23
-
23
+
24
+ # See httpstatuses.com
24
25
  CLIENT_ERRORS = {
25
26
  400 => :BadRequest,
26
27
  401 => :Unauthorized,
28
+ 402 => :PaymentRequired,
27
29
  403 => :Forbidden,
30
+ 404 => :NotFound,
31
+ 405 => :MethodNotAllowed,
28
32
  406 => :NotAcceptable,
33
+ 407 => :ProxyAuthenticationRequired,
34
+ 408 => :RequestTimeout,
35
+ 409 => :Conflict,
29
36
  410 => :Gone,
30
- 422 => :UnprocessableEntity }.freeze
31
-
37
+ 411 => :LengthRequired,
38
+ 412 => :PreconditionFailed,
39
+ 413 => :PayloadTooLarge,
40
+ 414 => :RequestUriTooLong,
41
+ 415 => :UnsupportedMediaType,
42
+ 416 => :RequestedRangeNotSatisfiable,
43
+ 417 => :ExpectationFailed,
44
+ 418 => :ImATeapot,
45
+ 421 => :MisdirectedRequest,
46
+ 422 => :UnprocessableEntity,
47
+ 423 => :Locked,
48
+ 424 => :FailedDependency,
49
+ 426 => :UpgradeRequired,
50
+ 428 => :PreconditionRequired,
51
+ 429 => :TooManyRequests,
52
+ 431 => :RequestHeaderFieldsTooLarge,
53
+ 444 => :ConnectionClosedWithoutResponse,
54
+ 451 => :UnavailableForLegalReasons,
55
+ 499 => :ClientClosedRequest }.freeze
56
+
57
+ # See httpstatuses.com
32
58
  SERVER_ERRORS = {
33
59
  500 => :InternalError,
60
+ 501 => :NotImplemented,
34
61
  502 => :BadGateway,
35
62
  503 => :ServiceUnavailable,
36
- 504 => :GatewayTimeout }.freeze
37
-
63
+ 504 => :GatewayTimeout,
64
+ 505 => :HttpVersionNotSupported,
65
+ 506 => :VariantAlsoNegotiates,
66
+ 507 => :InsufficientStorage,
67
+ 508 => :LoopDetected,
68
+ 510 => :NotExtended,
69
+ 511 => :NetworkAuthenticationRequired,
70
+ 599 => :NetworkConnectTimeoutError }.freeze
71
+
38
72
  ERRORS = CLIENT_ERRORS.merge(SERVER_ERRORS).freeze
39
-
73
+
40
74
  CLIENT_ERRORS.each do |code, error|
41
75
  const_set error, Class.new(Faraday::HTTP::ClientError)
42
76
  end
43
-
77
+
44
78
  SERVER_ERRORS.each do |code, error|
45
79
  const_set error, Class.new(Faraday::HTTP::ServerError)
46
80
  end
47
-
81
+
48
82
  end
49
83
  end
@@ -3,7 +3,7 @@ require "faraday/http_errors"
3
3
  require "faraday/raise_errors/version"
4
4
 
5
5
  module Faraday
6
-
6
+
7
7
  class RaiseErrors < ::Faraday::Response::Middleware
8
8
  def on_complete(env)
9
9
  case env[:status]
@@ -18,10 +18,10 @@ module Faraday
18
18
  raise exception.new(env)
19
19
  end
20
20
  end
21
-
21
+
22
22
  def response_values(env)
23
23
  { status: env[:status], headers: env[:response_headers], body: env[:body] }
24
24
  end
25
25
  end
26
-
26
+
27
27
  end
@@ -2,6 +2,6 @@ require "faraday"
2
2
 
3
3
  module Faraday
4
4
  class RaiseErrors < ::Faraday::Response::Middleware
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-raise-errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-27 00:00:00.000000000 Z
11
+ date: 2017-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.2.2
92
+ rubygems_version: 2.6.11
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Raises exceptions corresponding to HTTP responses