faraday 2.13.1 → 2.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ab8d55c7b360596e25721ecc32dcf99c65cea19d04598bb468fc2a422e26146
4
- data.tar.gz: 624ddc291aec0a438fded658897b2127d62b8fe10e00590e3ad0a609307711d6
3
+ metadata.gz: ba5077c825db9905310c665e101ad938f6e169dc9a887cbd03314434a7b37405
4
+ data.tar.gz: dc66440fa21267c217c7f5ee12d490eb039bcd6eed2b1efd727963c4d92eee16
5
5
  SHA512:
6
- metadata.gz: e2394c6ccb0b3e12d16e2dcd739d8ecf053199b40ce5d8d4a1902cc141c12746190e21b928e4979405ffcb2660db80a4777d46ee839df10f75cb66b34039285e
7
- data.tar.gz: d91f5258bb49c40ff720aaba295ab4c86ea975cb7e0d4ad96647921e34924013501c1b4dddcf1c5497488fda0480ef39296f76b16188201f0162da004a490ba5
6
+ metadata.gz: f55feaf0423e9169ad01017c18479dbac065fd1bce8403a82d841fac49e2845f420b0bb1bae5b3bf1b1dba5dbc03796f10997ea8ec7c15148b8ed1f5770cd81b
7
+ data.tar.gz: 875b2d50d365f7771e825949a483b433e7c87a969bb721c6024cb575832ddf02013c9252be5c2285008c4d4177ce9d085caaeb4940b014db5b505ed6bd25c226
data/lib/faraday/error.rb CHANGED
@@ -79,12 +79,25 @@ module Faraday
79
79
 
80
80
  # Pulls out potential parent exception and response hash.
81
81
  def exc_msg_and_response(exc, response = nil)
82
- return [exc, exc.message, response] if exc.respond_to?(:backtrace)
83
-
84
- return [nil, "the server responded with status #{exc[:status]}", exc] \
85
- if exc.respond_to?(:each_key)
86
-
87
- [nil, exc.to_s, response]
82
+ if exc.is_a?(Exception)
83
+ [exc, exc.message, response]
84
+ elsif exc.is_a?(Hash)
85
+ http_status = exc.fetch(:status)
86
+
87
+ request = exc.fetch(:request, nil)
88
+
89
+ if request.nil?
90
+ exception_message = "the server responded with status #{http_status} - method and url are not available " \
91
+ 'due to include_request: false on Faraday::Response::RaiseError middleware'
92
+ else
93
+ exception_message = "the server responded with status #{http_status} for #{request.fetch(:method).upcase} " \
94
+ "#{request.fetch(:url)}"
95
+ end
96
+
97
+ [nil, exception_message, exc]
98
+ else
99
+ [nil, exc.to_s, response]
100
+ end
88
101
  end
89
102
  end
90
103
 
@@ -221,7 +221,7 @@ module Faraday
221
221
  end
222
222
 
223
223
  def raise_if_adapter(klass)
224
- return unless is_adapter?(klass)
224
+ return unless klass <= Faraday::Adapter
225
225
 
226
226
  raise 'Adapter should be set using the `adapter` method, not `use`'
227
227
  end
@@ -234,10 +234,6 @@ module Faraday
234
234
  !@adapter.nil?
235
235
  end
236
236
 
237
- def is_adapter?(klass) # rubocop:disable Naming/PredicateName
238
- klass <= Faraday::Adapter
239
- end
240
-
241
237
  def use_symbol(mod, key, ...)
242
238
  use(mod.lookup_middleware(key), ...)
243
239
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.13.1'
4
+ VERSION = '2.13.2'
5
5
  end
data/lib/faraday.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cgi'
3
+ require 'cgi/escape'
4
+ require 'cgi/util' if RUBY_VERSION < '3.5'
4
5
  require 'date'
5
6
  require 'set'
6
7
  require 'forwardable'
@@ -23,7 +23,7 @@ RSpec.describe Faraday::Error do
23
23
 
24
24
  it { expect(subject.wrapped_exception).to be_nil }
25
25
  it { expect(subject.response).to eq(exception) }
26
- it { expect(subject.message).to eq('the server responded with status 400') }
26
+ it { expect(subject.message).to eq('the server responded with status 400 - method and url are not available due to include_request: false on Faraday::Response::RaiseError middleware') }
27
27
  if RUBY_VERSION >= '3.4'
28
28
  it { expect(subject.inspect).to eq('#<Faraday::Error response={status: 400}>') }
29
29
  else
@@ -28,7 +28,7 @@ RSpec.describe Faraday::Response::RaiseError do
28
28
 
29
29
  it 'raises Faraday::BadRequestError for 400 responses' do
30
30
  expect { conn.get('bad-request') }.to raise_error(Faraday::BadRequestError) do |ex|
31
- expect(ex.message).to eq('the server responded with status 400')
31
+ expect(ex.message).to eq('the server responded with status 400 for GET http:/bad-request')
32
32
  expect(ex.response[:headers]['X-Reason']).to eq('because')
33
33
  expect(ex.response[:status]).to eq(400)
34
34
  expect(ex.response_status).to eq(400)
@@ -39,7 +39,7 @@ RSpec.describe Faraday::Response::RaiseError do
39
39
 
40
40
  it 'raises Faraday::UnauthorizedError for 401 responses' do
41
41
  expect { conn.get('unauthorized') }.to raise_error(Faraday::UnauthorizedError) do |ex|
42
- expect(ex.message).to eq('the server responded with status 401')
42
+ expect(ex.message).to eq('the server responded with status 401 for GET http:/unauthorized')
43
43
  expect(ex.response[:headers]['X-Reason']).to eq('because')
44
44
  expect(ex.response[:status]).to eq(401)
45
45
  expect(ex.response_status).to eq(401)
@@ -50,7 +50,7 @@ RSpec.describe Faraday::Response::RaiseError do
50
50
 
51
51
  it 'raises Faraday::ForbiddenError for 403 responses' do
52
52
  expect { conn.get('forbidden') }.to raise_error(Faraday::ForbiddenError) do |ex|
53
- expect(ex.message).to eq('the server responded with status 403')
53
+ expect(ex.message).to eq('the server responded with status 403 for GET http:/forbidden')
54
54
  expect(ex.response[:headers]['X-Reason']).to eq('because')
55
55
  expect(ex.response[:status]).to eq(403)
56
56
  expect(ex.response_status).to eq(403)
@@ -61,7 +61,7 @@ RSpec.describe Faraday::Response::RaiseError do
61
61
 
62
62
  it 'raises Faraday::ResourceNotFound for 404 responses' do
63
63
  expect { conn.get('not-found') }.to raise_error(Faraday::ResourceNotFound) do |ex|
64
- expect(ex.message).to eq('the server responded with status 404')
64
+ expect(ex.message).to eq('the server responded with status 404 for GET http:/not-found')
65
65
  expect(ex.response[:headers]['X-Reason']).to eq('because')
66
66
  expect(ex.response[:status]).to eq(404)
67
67
  expect(ex.response_status).to eq(404)
@@ -83,7 +83,7 @@ RSpec.describe Faraday::Response::RaiseError do
83
83
 
84
84
  it 'raises Faraday::RequestTimeoutError for 408 responses' do
85
85
  expect { conn.get('request-timeout') }.to raise_error(Faraday::RequestTimeoutError) do |ex|
86
- expect(ex.message).to eq('the server responded with status 408')
86
+ expect(ex.message).to eq('the server responded with status 408 for GET http:/request-timeout')
87
87
  expect(ex.response[:headers]['X-Reason']).to eq('because')
88
88
  expect(ex.response[:status]).to eq(408)
89
89
  expect(ex.response_status).to eq(408)
@@ -94,7 +94,7 @@ RSpec.describe Faraday::Response::RaiseError do
94
94
 
95
95
  it 'raises Faraday::ConflictError for 409 responses' do
96
96
  expect { conn.get('conflict') }.to raise_error(Faraday::ConflictError) do |ex|
97
- expect(ex.message).to eq('the server responded with status 409')
97
+ expect(ex.message).to eq('the server responded with status 409 for GET http:/conflict')
98
98
  expect(ex.response[:headers]['X-Reason']).to eq('because')
99
99
  expect(ex.response[:status]).to eq(409)
100
100
  expect(ex.response_status).to eq(409)
@@ -105,7 +105,7 @@ RSpec.describe Faraday::Response::RaiseError do
105
105
 
106
106
  it 'raises Faraday::UnprocessableEntityError for 422 responses' do
107
107
  expect { conn.get('unprocessable-entity') }.to raise_error(Faraday::UnprocessableEntityError) do |ex|
108
- expect(ex.message).to eq('the server responded with status 422')
108
+ expect(ex.message).to eq('the server responded with status 422 for GET http:/unprocessable-entity')
109
109
  expect(ex.response[:headers]['X-Reason']).to eq('because')
110
110
  expect(ex.response[:status]).to eq(422)
111
111
  expect(ex.response_status).to eq(422)
@@ -116,7 +116,7 @@ RSpec.describe Faraday::Response::RaiseError do
116
116
 
117
117
  it 'raises Faraday::TooManyRequestsError for 429 responses' do
118
118
  expect { conn.get('too-many-requests') }.to raise_error(Faraday::TooManyRequestsError) do |ex|
119
- expect(ex.message).to eq('the server responded with status 429')
119
+ expect(ex.message).to eq('the server responded with status 429 for GET http:/too-many-requests')
120
120
  expect(ex.response[:headers]['X-Reason']).to eq('because')
121
121
  expect(ex.response[:status]).to eq(429)
122
122
  expect(ex.response_status).to eq(429)
@@ -138,7 +138,7 @@ RSpec.describe Faraday::Response::RaiseError do
138
138
 
139
139
  it 'raises Faraday::ClientError for other 4xx responses' do
140
140
  expect { conn.get('4xx') }.to raise_error(Faraday::ClientError) do |ex|
141
- expect(ex.message).to eq('the server responded with status 499')
141
+ expect(ex.message).to eq('the server responded with status 499 for GET http:/4xx')
142
142
  expect(ex.response[:headers]['X-Reason']).to eq('because')
143
143
  expect(ex.response[:status]).to eq(499)
144
144
  expect(ex.response_status).to eq(499)
@@ -149,7 +149,7 @@ RSpec.describe Faraday::Response::RaiseError do
149
149
 
150
150
  it 'raises Faraday::ServerError for 500 responses' do
151
151
  expect { conn.get('server-error') }.to raise_error(Faraday::ServerError) do |ex|
152
- expect(ex.message).to eq('the server responded with status 500')
152
+ expect(ex.message).to eq('the server responded with status 500 for GET http:/server-error')
153
153
  expect(ex.response[:headers]['X-Error']).to eq('bailout')
154
154
  expect(ex.response[:status]).to eq(500)
155
155
  expect(ex.response_status).to eq(500)
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.13.1
4
+ version: 2.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -144,7 +144,7 @@ licenses:
144
144
  - MIT
145
145
  metadata:
146
146
  homepage_uri: https://lostisland.github.io/faraday
147
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.13.1
147
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.13.2
148
148
  source_code_uri: https://github.com/lostisland/faraday
149
149
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
150
150
  rubygems_mfa_required: 'true'