files.com 1.0.487 → 1.0.489

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: b7b26950c315d418ad5a98128863c5e09a92513a6b61c69c0f124355c50979fa
4
- data.tar.gz: 35d0001958e3d7cd9c683ab85c13c7068284a281701f9848b3ab3a10f03c21ce
3
+ metadata.gz: 49b3844533ed4909393b8aae11c3d93e34c3a759359f56bd729a84506c4717fb
4
+ data.tar.gz: 520b129ef503040f177693b9c9ca5a48ba9d96284ecd89c27eafd2b5a3684339
5
5
  SHA512:
6
- metadata.gz: 17f5f0610765f124fa5b9612169094e5523da4b5acadb80a4274bacf5ef4c65a35506dac1474a71c21366581453c1e56d8ac7ab5fb576ef20fd2ac20a3f7bdf9
7
- data.tar.gz: 70990797609a9c7017fa96d260d358418bf30d0a11a4b503a26534df0cb66c64d11f801f0e7796c1dd8e7916a2b2e83e339bf2adce44d1c492704a9ccf392dc3
6
+ metadata.gz: 52aadff7b257ed2f8efe152746943171bd81859f40c372549c26f163b3e87c689f0cabb240ad8de0364d5a8199fd8c2a8fa8f5e5baa0029ce71b4ff31da31952
7
+ data.tar.gz: eb870b33b971d253bed90c642ac9f278fad7a8856dff3ff99eacc392e3d89657ef21269b7f0b76f6db559fd73db3ad00b18be364c6e64b9619939e66e86a09a8
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.487
1
+ 1.0.489
@@ -236,12 +236,11 @@ module Files
236
236
 
237
237
  case e
238
238
  when Faraday::ClientError, Faraday::ServerError
239
- if e.response
239
+ if e.response and has_error_type?(e)
240
240
  handle_error_response(e.response, error_context)
241
241
  else
242
242
  handle_network_error(e, error_context, num_retries, base_url)
243
243
  end
244
-
245
244
  else
246
245
  raise
247
246
  end
@@ -302,13 +301,15 @@ module Files
302
301
  end
303
302
  end
304
303
 
305
- private def handle_network_error(error, context, num_retries, base_url = nil)
304
+ private def handle_network_error(error, _context, num_retries, base_url = nil)
306
305
  base_url ||= Files.base_url
307
306
 
308
- Util.log_error("Network error", error_message: error.message, request_id: context.request_id)
307
+ error_message = error.message.empty? ? error.response[:body] : error.message
308
+
309
+ Util.log_error("Network error", error_message: error_message)
309
310
  message = "Could not connect to Files.com at URL #{base_url}. Please check your internet connection and try again. If this problem persists, you should check Files.com's service status at https://status.files.com, or contact your primary account representative."
310
311
  message += " Request was retried #{num_retries} times." if num_retries > 0
311
- message += "\n\n(Network error: #{error.message})"
312
+ message += "\n\n(Network error: #{error_message})"
312
313
 
313
314
  raise APIConnectionError, message
314
315
  end
@@ -337,6 +338,12 @@ module Files
337
338
  headers
338
339
  end
339
340
 
341
+ private def has_error_type?(e)
342
+ Response.from_faraday_hash(e.response).data&.dig(:type) ? true : false
343
+ rescue JSON::ParserError, Error
344
+ false
345
+ end
346
+
340
347
  private def log_request(context, num_retries, no_body: false)
341
348
  Util.log_info("Request", method: context.method, num_retries: num_retries, path: context.path)
342
349
  Util.log_debug("Request details", body: context.body, query_params: context.query_params) unless no_body
@@ -186,6 +186,8 @@ module Files
186
186
  class ResourceLockedError < ProcessingFailureError; end
187
187
  class SubfolderLockedError < ProcessingFailureError; end
188
188
  class TwoFactorAuthenticationCodeAlreadySentError < ProcessingFailureError; end
189
+ class TwoFactorAuthenticationCountryBlacklistedError < ProcessingFailureError; end
190
+ class TwoFactorAuthenticationGeneralErrorError < ProcessingFailureError; end
189
191
  class UpdatesNotAllowedForRemotesError < ProcessingFailureError; end
190
192
 
191
193
  class RateLimitedError < APIError; end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Files
4
- VERSION = "1.0.487"
4
+ VERSION = "1.0.489"
5
5
  end
@@ -11,20 +11,20 @@ RSpec.describe Files::ApiClient do
11
11
  allow(subject).to receive(:log_request).and_raise(Faraday::ServerError.new('', mock_response))
12
12
  end
13
13
 
14
- it 'retries with sleeps and raises general api error' do
14
+ it 'retries with sleeps and raises general api connection error' do
15
15
  expect(subject).to receive(:sleep).with(0.5).ordered
16
16
  expect(subject).to receive(:sleep).with(be_between(0.5, 1)).ordered
17
17
  expect(subject).to receive(:sleep).with(be_between(1, 2)).ordered
18
18
  expect {
19
19
  subject.execute_request_with_rescues(1, context) { 'empty block' }
20
- }.to raise_error(Files::APIError, error_message)
20
+ }.to raise_error(Files::APIConnectionError, error_message)
21
21
  end
22
22
  end
23
23
 
24
24
  context 'when response is a valid json' do
25
25
  it_behaves_like 'a server error handler' do
26
- let(:error_message) { "Server Error" }
27
- let(:mock_response) { { status: 502, headers: {}, body: { error: error_message }.to_json } }
26
+ let(:error_message) { "Could not connect to Files.com at URL 1. Please check your internet connection and try again. If this problem persists, you should check Files.com's service status at https://status.files.com, or contact your primary account representative. Request was retried 3 times.\n\n(Network error: {\"error\":\"Server Error\"})" }
27
+ let(:mock_response) { { status: 502, headers: {}, body: { error: "Server Error" }.to_json } }
28
28
  end
29
29
  end
30
30
 
@@ -37,8 +37,50 @@ RSpec.describe Files::ApiClient do
37
37
  body: "<html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center><hr><center>files.com</center></body></html>"
38
38
  }
39
39
  }
40
- let(:error_message) { "Unexpected response object from API: \"#{mock_response[:body]}\" (HTTP response code was 502)" }
40
+ let(:error_message) { "Could not connect to Files.com at URL 1. Please check your internet connection and try again. If this problem persists, you should check Files.com's service status at https://status.files.com, or contact your primary account representative. Request was retried 3 times.\n\n(Network error: <html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center><hr><center>files.com</center></body></html>)" }
41
41
  end
42
42
  end
43
43
  end
44
+
45
+ describe "#specific_api_error" do
46
+ let(:context) { double('context', method: 'some method', path: 'some path') }
47
+ let(:bad_request_with_data) {
48
+ {
49
+ error: "The request parameter path cannot have trailing whitespace: . /+testing previews.",
50
+ 'http-code': 400,
51
+ instance: "23825f04-7add-4911-b9d7-f4342a75a471",
52
+ title: "Request Param Path Cannot Have Trailing Whitespace",
53
+ type: "bad-request/request-param-path-cannot-have-trailing-whitespace"
54
+ }
55
+ }
56
+ let(:bad_request_without_data) {
57
+ {
58
+ error: 'Bad Request'
59
+ }
60
+ }
61
+ let(:mock_good_response) { { status: 400, headers: {}, body: bad_request_with_data.to_json } }
62
+ let(:mock_response_without_type) { { status: 400, headers: {}, body: bad_request_without_data.to_json } }
63
+ let(:mock_empty_response) { { status: 400, headers: {}, body: '' } }
64
+
65
+ it "handles correctly when bad request with data and proper error type" do
66
+ allow(subject).to receive(:log_request).and_raise(Faraday::BadRequestError.new('', mock_good_response))
67
+ expect {
68
+ subject.execute_request_with_rescues(1, context) { 'empty block' }
69
+ }.to raise_error(Files::RequestParamPathCannotHaveTrailingWhitespaceError, bad_request_with_data[:error])
70
+ end
71
+
72
+ it "throws generic bad request error when no type" do
73
+ allow(subject).to receive(:log_request).and_raise(Faraday::BadRequestError.new('', mock_response_without_type))
74
+ expect {
75
+ subject.execute_request_with_rescues(1, context) { 'empty block' }
76
+ }.to raise_error(Files::APIConnectionError)
77
+ end
78
+
79
+ it "throws generic bad request error when no body at all" do
80
+ allow(subject).to receive(:log_request).and_raise(Faraday::BadRequestError.new('', mock_empty_response))
81
+ expect {
82
+ subject.execute_request_with_rescues(1, context) { 'empty block' }
83
+ }.to raise_error(Files::APIConnectionError)
84
+ end
85
+ end
44
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: files.com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.487
4
+ version: 1.0.489
5
5
  platform: ruby
6
6
  authors:
7
7
  - files.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-15 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable