faraday 2.11.0 → 2.12.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
  SHA256:
3
- metadata.gz: 7ceee5efaef78f039d68da91b621e8ae3723f6663fc11667709845b08358bb53
4
- data.tar.gz: 430834e5a0cecbc636eecf485eae7061447126e93b5de5f27ad2d7a938a36459
3
+ metadata.gz: 22c3a83dd32f012eb6d4bf4fe79b3e95ce44979ac19aee42a533d88f5c27848e
4
+ data.tar.gz: c07d8eda18dcde723ee2ab365a5d46272c88dab63cbadecd7f3d4af6e6133f9e
5
5
  SHA512:
6
- metadata.gz: 9664749d4913670b04ed973554bf2893fb17f63eb5117a86a36d083615421cbca07212f4797e2869f1ec86905e428f9de89c913c142464bdb6764316ad4edeae
7
- data.tar.gz: c2d7c4259cfceb8f862e4ea45f8bf7f8f3a7c1896478b882f349539270aac8161fb079b29b0f4fa29b57539a395e9a9d7f62f65ecd76433746373dc0243200b4
6
+ metadata.gz: 728dafd34ea29e515627f14bb254c83729ca66470961505d332994bf9ee52de85d43b97969fd0ce5cb9db22fbdf43b8ac0d64ee9447c336f5fcc6be6adc0d737
7
+ data.tar.gz: 1f28a98be9151d77ec729cabc40faa0c11cc27283382925452e6076e20cc5321b63732492d9dc10fb65a35977b18b957e636e72e22686c2467d91de9a038fae8
@@ -8,32 +8,30 @@ module Faraday
8
8
  # rubocop:disable Naming/ConstantName
9
9
  ClientErrorStatuses = (400...500)
10
10
  ServerErrorStatuses = (500...600)
11
+ ClientErrorStatusesWithCustomExceptions = {
12
+ 400 => Faraday::BadRequestError,
13
+ 401 => Faraday::UnauthorizedError,
14
+ 403 => Faraday::ForbiddenError,
15
+ 404 => Faraday::ResourceNotFound,
16
+ 408 => Faraday::RequestTimeoutError,
17
+ 409 => Faraday::ConflictError,
18
+ 422 => Faraday::UnprocessableEntityError,
19
+ 429 => Faraday::TooManyRequestsError
20
+ }.freeze
11
21
  # rubocop:enable Naming/ConstantName
12
22
 
13
- DEFAULT_OPTIONS = { include_request: true }.freeze
23
+ DEFAULT_OPTIONS = { include_request: true, allowed_statuses: [] }.freeze
14
24
 
15
25
  def on_complete(env)
26
+ return if Array(options[:allowed_statuses]).include?(env[:status])
27
+
16
28
  case env[:status]
17
- when 400
18
- raise Faraday::BadRequestError, response_values(env)
19
- when 401
20
- raise Faraday::UnauthorizedError, response_values(env)
21
- when 403
22
- raise Faraday::ForbiddenError, response_values(env)
23
- when 404
24
- raise Faraday::ResourceNotFound, response_values(env)
29
+ when *ClientErrorStatusesWithCustomExceptions.keys
30
+ raise ClientErrorStatusesWithCustomExceptions[env[:status]], response_values(env)
25
31
  when 407
26
32
  # mimic the behavior that we get with proxy requests with HTTPS
27
33
  msg = %(407 "Proxy Authentication Required")
28
34
  raise Faraday::ProxyAuthError.new(msg, response_values(env))
29
- when 408
30
- raise Faraday::RequestTimeoutError, response_values(env)
31
- when 409
32
- raise Faraday::ConflictError, response_values(env)
33
- when 422
34
- raise Faraday::UnprocessableEntityError, response_values(env)
35
- when 429
36
- raise Faraday::TooManyRequestsError, response_values(env)
37
35
  when ClientErrorStatuses
38
36
  raise Faraday::ClientError, response_values(env)
39
37
  when ServerErrorStatuses
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.11.0'
4
+ VERSION = '2.12.0'
5
5
  end
@@ -252,4 +252,24 @@ RSpec.describe Faraday::Response::RaiseError do
252
252
  end
253
253
  end
254
254
  end
255
+
256
+ describe 'allowing certain status codes' do
257
+ let(:conn) do
258
+ Faraday.new do |b|
259
+ b.response :raise_error, allowed_statuses: [404]
260
+ b.adapter :test do |stub|
261
+ stub.get('bad-request') { [400, { 'X-Reason' => 'because' }, 'keep looking'] }
262
+ stub.get('not-found') { [404, { 'X-Reason' => 'because' }, 'keep looking'] }
263
+ end
264
+ end
265
+ end
266
+
267
+ it 'raises an error for status codes that are not explicitly allowed' do
268
+ expect { conn.get('bad-request') }.to raise_error(Faraday::BadRequestError)
269
+ end
270
+
271
+ it 'does not raise an error for allowed status codes' do
272
+ expect { conn.get('not-found') }.not_to raise_error
273
+ end
274
+ end
255
275
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-08-26 00:00:00.000000000 Z
13
+ date: 2024-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday-net_http
@@ -32,6 +32,20 @@ dependencies:
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '3.4'
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
35
49
  - !ruby/object:Gem::Dependency
36
50
  name: logger
37
51
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +146,7 @@ licenses:
132
146
  - MIT
133
147
  metadata:
134
148
  homepage_uri: https://lostisland.github.io/faraday
135
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.11.0
149
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.12.0
136
150
  source_code_uri: https://github.com/lostisland/faraday
137
151
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
138
152
  rubygems_mfa_required: 'true'
@@ -152,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
166
  - !ruby/object:Gem::Version
153
167
  version: '0'
154
168
  requirements: []
155
- rubygems_version: 3.5.11
169
+ rubygems_version: 3.5.16
156
170
  signing_key:
157
171
  specification_version: 4
158
172
  summary: HTTP/REST API client library.