dear_inventory 1.5.2 → 1.6.0
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f50f5fccdaf7007a7f7d80ebf08745d50b0cc7243a445cfc4c4a13d197533a79
|
|
4
|
+
data.tar.gz: 2713ad24418a84bcc12ace816ef59e21a48cdd40ebeed3dbff5b4999863c69f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d942ed12b4022323851b4a285ab1fc1cd8356c7a8a99528ae2050ddfc8237d91b5e9994224dbfc30185f0f7fab2a1fcc823802183ad53cc41bf2fb01169baed5
|
|
7
|
+
data.tar.gz: 87114e0054e9e3444cb8aa01d6315c5c9322dd0e2070e97938f60353e36d623ffbd32ae347d85556036b9ea5863f335792a2bc0e7872c2cb0d48ad035d24c69c
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module DearInventory
|
|
4
|
-
class APILimitError < DearInventory::
|
|
4
|
+
class APILimitError < DearInventory::RequestError
|
|
5
|
+
# Cin7 sends "60 Seconds" in Retry-After rather than the delta-seconds or
|
|
6
|
+
# HTTP-date that RFC 9110 allows, so only a leading integer can be trusted.
|
|
7
|
+
# X-RateLimit-Reset carries the same value as a bare integer
|
|
8
|
+
def retry_after
|
|
9
|
+
return if response.nil?
|
|
10
|
+
|
|
11
|
+
reset = response.headers["X-RateLimit-Reset"]
|
|
12
|
+
return reset.to_i unless reset.nil?
|
|
13
|
+
|
|
14
|
+
response.headers["Retry-After"].to_s[/\A\d+/]&.to_i
|
|
15
|
+
end
|
|
16
|
+
end
|
|
5
17
|
end
|
|
@@ -56,7 +56,7 @@ module DearInventory
|
|
|
56
56
|
raise if @retries >= MAX_RETRIES
|
|
57
57
|
|
|
58
58
|
message_prefix = ERROR_MESSAGE_PREFIXES[error.class]
|
|
59
|
-
retry_time =
|
|
59
|
+
retry_time = retry_delay(error)
|
|
60
60
|
|
|
61
61
|
DearInventory.config.logger.warn(
|
|
62
62
|
"#{message_prefix} while fetching #{@parameters.uri}. " \
|
|
@@ -66,5 +66,12 @@ module DearInventory
|
|
|
66
66
|
sleep(retry_time)
|
|
67
67
|
call
|
|
68
68
|
end
|
|
69
|
+
|
|
70
|
+
def retry_delay(error)
|
|
71
|
+
backoff = @retries * RETRY_DELAY
|
|
72
|
+
return backoff unless error.is_a?(DearInventory::APILimitError)
|
|
73
|
+
|
|
74
|
+
error.retry_after || backoff
|
|
75
|
+
end
|
|
69
76
|
end
|
|
70
77
|
end
|
|
@@ -134,10 +134,13 @@ module DearInventory
|
|
|
134
134
|
def raise_error
|
|
135
135
|
raise DearInventory::BadRequestError.new(error, self) if http_status == 400
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
# Cin7 reported the rate limit as a 503 until 2026. The message is still
|
|
138
|
+
# checked for that status because a 503 is also a genuine outage
|
|
139
|
+
if http_status == 429 || (http_status == 503 && error == API_LIMIT_ERROR)
|
|
140
|
+
raise DearInventory::APILimitError.new(error, self)
|
|
141
|
+
end
|
|
138
142
|
|
|
139
|
-
raise DearInventory::Error
|
|
140
|
-
new("Unknown error (#{http_status}): #{error}")
|
|
143
|
+
raise DearInventory::Error, "Unknown error (#{http_status}): #{error}"
|
|
141
144
|
end
|
|
142
145
|
|
|
143
146
|
def iterate_over_records(response, block)
|
data/lib/dear_inventory.rb
CHANGED
|
@@ -6,12 +6,12 @@ require "dear_inventory/config"
|
|
|
6
6
|
require "dear_inventory/environment"
|
|
7
7
|
|
|
8
8
|
require "dear_inventory/error"
|
|
9
|
-
require "dear_inventory/errors/api_limit"
|
|
10
9
|
require "dear_inventory/errors/no_more_pages"
|
|
11
10
|
require "dear_inventory/errors/not_paginated"
|
|
12
11
|
require "dear_inventory/errors/validation"
|
|
13
12
|
|
|
14
13
|
require "dear_inventory/errors/request"
|
|
14
|
+
require "dear_inventory/errors/api_limit"
|
|
15
15
|
require "dear_inventory/errors/bad_request"
|
|
16
16
|
|
|
17
17
|
require "dear_inventory/lib/endpoint_class"
|