files.com 1.0.486 → 1.0.488

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: 322c6e72224efa5614973b2af891e64fa439ae20abf0c7660b53ff4c2b54055c
4
- data.tar.gz: 3e32e5563c2c663634074e5639674fe5b734c4ba8de49829e454cab4ca9c596a
3
+ metadata.gz: 1be0c3961f1c2d64351b352e054d27ca5e0224457c7328d3082bca7c233707d7
4
+ data.tar.gz: ddda72daeb4660814c6b663b0f716425fd3168173b92178e60cad9aef78ffbd7
5
5
  SHA512:
6
- metadata.gz: 75490c41da14ebe46d5dca8c79653a9b8158dbe14297d3888ac1bde6cca684e36aa8c6be063360f9b05aae2dd8940104bb5efa3a9d23469f7e23a425fc85fe35
7
- data.tar.gz: d6546b9dbbc10027955c872401c395f7a722b5528b8c2c4ef214a80c4747fe47b6bedbeae72babed3bc8f34d5296f109dff1574651f058f28090528ebda6aa7b
6
+ metadata.gz: 4f8542508603e1b873829c75d3fbefca19d4d226d0fdcba9aac3d73e3348e8bbd8f1e91edd17d6c4421be6715b798a95f30154a63d19bbc91849faa1dc9dafc2
7
+ data.tar.gz: 150a8b8acfeaf6233b253abf97026da469a2a9f5ce245608c48daa2dfae582bd60844fd3ed3d4d09515f240af742e869d313c48b7c68ceb100bd1e3fd767e59d
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.486
1
+ 1.0.488
@@ -235,10 +235,12 @@ module Files
235
235
  end
236
236
 
237
237
  case e
238
- when Faraday::ClientError
239
- handle_error_response(e.response, error_context)
240
- when Faraday::ServerError
241
- handle_network_error(e, error_context, num_retries, base_url)
238
+ when Faraday::ClientError, Faraday::ServerError
239
+ if e.response and has_error_type?(e)
240
+ handle_error_response(e.response, error_context)
241
+ else
242
+ handle_network_error(e, error_context, num_retries, base_url)
243
+ end
242
244
  else
243
245
  raise
244
246
  end
@@ -302,10 +304,12 @@ module Files
302
304
  private def handle_network_error(error, _context, num_retries, base_url = nil)
303
305
  base_url ||= Files.base_url
304
306
 
305
- Util.log_error("Network error", error_message: error.message)
307
+ error_message = error.message.empty? ? error.response[:body] : error.message
308
+
309
+ Util.log_error("Network error", error_message: error_message)
306
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."
307
311
  message += " Request was retried #{num_retries} times." if num_retries > 0
308
- message += "\n\n(Network error: #{error.message})"
312
+ message += "\n\n(Network error: #{error_message})"
309
313
 
310
314
  raise APIConnectionError, message
311
315
  end
@@ -334,6 +338,12 @@ module Files
334
338
  headers
335
339
  end
336
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
+
337
347
  private def log_request(context, num_retries, no_body: false)
338
348
  Util.log_info("Request", method: context.method, num_retries: num_retries, path: context.path)
339
349
  Util.log_debug("Request details", body: context.body, query_params: context.query_params) unless no_body
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Files
4
- VERSION = "1.0.486"
4
+ VERSION = "1.0.488"
5
5
  end
@@ -1,5 +1,4 @@
1
1
  require "spec_helper"
2
- require "pry"
3
2
 
4
3
  RSpec.describe Files::ApiClient do
5
4
  let(:subject) { described_class.new }
@@ -9,7 +8,7 @@ RSpec.describe Files::ApiClient do
9
8
 
10
9
  shared_examples 'a server error handler' do
11
10
  before do
12
- allow(subject).to receive(:log_request).and_raise(Faraday::ServerError.new('the server responded with status 502', mock_response))
11
+ allow(subject).to receive(:log_request).and_raise(Faraday::ServerError.new('', mock_response))
13
12
  end
14
13
 
15
14
  it 'retries with sleeps and raises general api connection error' do
@@ -24,8 +23,8 @@ RSpec.describe Files::ApiClient do
24
23
 
25
24
  context 'when response is a valid json' do
26
25
  it_behaves_like 'a server error handler' do
27
- 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: the server responded with status 502)" }
28
- 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 } }
29
28
  end
30
29
  end
31
30
 
@@ -38,8 +37,50 @@ RSpec.describe Files::ApiClient do
38
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>"
39
38
  }
40
39
  }
41
- 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: the server responded with status 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>)" }
42
41
  end
43
42
  end
44
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
45
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.486
4
+ version: 1.0.488
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-14 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable