runapi-core 0.2.12 → 0.2.13
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 +4 -4
- data/lib/runapi/core/errors.rb +25 -1
- data/lib/runapi/core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 54af25cbee562bbd98fffc58f942ef47c0aca7ec192fce354ee838193ddca938
|
|
4
|
+
data.tar.gz: 7267f1f89df5153b8f48ba7c16ff638a911447c22bd5c64767e166f24092375e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b68a3396f9ee702efc8396d5e69e2fb56f83462d38a0fed5eaafd2230c61b93dd68128929ac32d60b1dbe6d716e4381c47d0715ef0aeeb144a9eacd03857f78
|
|
7
|
+
data.tar.gz: 68f6599bdb9958021c82a77da85b7f10ef3d1f3779370bc215cbbb89ab1d434762e75b387ea5fdaa456cf600878f7bd14aa6b353f710961a1ad9554b56d83b73
|
data/lib/runapi/core/errors.rb
CHANGED
|
@@ -9,6 +9,8 @@ module RunApi
|
|
|
9
9
|
class Error < StandardError
|
|
10
10
|
# @return [Integer, nil] HTTP status code if available.
|
|
11
11
|
attr_reader :status
|
|
12
|
+
# @return [String, nil] Explicit machine-readable reason.
|
|
13
|
+
attr_reader :code
|
|
12
14
|
# @return [String, nil] Request ID from response headers.
|
|
13
15
|
attr_reader :request_id
|
|
14
16
|
# @return [Hash, String, nil] Parsed response body or error details.
|
|
@@ -16,8 +18,9 @@ module RunApi
|
|
|
16
18
|
# @return [ResponseHeaders] HTTP response headers when available.
|
|
17
19
|
attr_reader :response_headers
|
|
18
20
|
|
|
19
|
-
def initialize(message = nil, status: nil, request_id: nil, details: nil, response_headers: nil)
|
|
21
|
+
def initialize(message = nil, code: nil, status: nil, request_id: nil, details: nil, response_headers: nil)
|
|
20
22
|
super(message)
|
|
23
|
+
@code = code
|
|
21
24
|
@status = status
|
|
22
25
|
@request_id = request_id
|
|
23
26
|
@details = details
|
|
@@ -36,6 +39,7 @@ module RunApi
|
|
|
36
39
|
{
|
|
37
40
|
error: self.class.name,
|
|
38
41
|
message: message,
|
|
42
|
+
code: code,
|
|
39
43
|
status: status,
|
|
40
44
|
request_id: request_id,
|
|
41
45
|
details: details
|
|
@@ -99,6 +103,7 @@ module RunApi
|
|
|
99
103
|
end
|
|
100
104
|
|
|
101
105
|
kwargs = {
|
|
106
|
+
code: extract_code(parsed_body),
|
|
102
107
|
status: status,
|
|
103
108
|
request_id: request_id,
|
|
104
109
|
details: parsed_body,
|
|
@@ -148,6 +153,13 @@ module RunApi
|
|
|
148
153
|
body["msg"]
|
|
149
154
|
end
|
|
150
155
|
|
|
156
|
+
def extract_code(body)
|
|
157
|
+
return nil unless body.is_a?(Hash)
|
|
158
|
+
|
|
159
|
+
code = body.dig("error", "code") if body["error"].is_a?(Hash)
|
|
160
|
+
(code.is_a?(String) && !code.empty?) ? code : nil
|
|
161
|
+
end
|
|
162
|
+
|
|
151
163
|
def parse_retry_after(value)
|
|
152
164
|
return nil if value.nil?
|
|
153
165
|
|
|
@@ -174,6 +186,7 @@ module RunApi
|
|
|
174
186
|
# Raised when API key is missing or invalid (HTTP 401).
|
|
175
187
|
class AuthenticationError < Error
|
|
176
188
|
def initialize(message = "Unauthorized", **kwargs)
|
|
189
|
+
kwargs[:code] = "authentication" unless kwargs.key?(:code)
|
|
177
190
|
super(message, status: 401, **kwargs)
|
|
178
191
|
end
|
|
179
192
|
end
|
|
@@ -184,6 +197,7 @@ module RunApi
|
|
|
184
197
|
attr_reader :retry_after
|
|
185
198
|
|
|
186
199
|
def initialize(message = "Too many requests", retry_after: nil, **kwargs)
|
|
200
|
+
kwargs[:code] = "rate_limit" unless kwargs.key?(:code)
|
|
187
201
|
super(message, status: 429, **kwargs)
|
|
188
202
|
@retry_after = retry_after
|
|
189
203
|
end
|
|
@@ -192,6 +206,7 @@ module RunApi
|
|
|
192
206
|
# Raised when account has insufficient credits (HTTP 402).
|
|
193
207
|
class InsufficientCreditsError < Error
|
|
194
208
|
def initialize(message = "Insufficient credits", **kwargs)
|
|
209
|
+
kwargs[:code] = "insufficient_credits" unless kwargs.key?(:code)
|
|
195
210
|
super(message, status: 402, **kwargs)
|
|
196
211
|
end
|
|
197
212
|
end
|
|
@@ -199,6 +214,7 @@ module RunApi
|
|
|
199
214
|
# Raised when requested resource does not exist (HTTP 404).
|
|
200
215
|
class NotFoundError < Error
|
|
201
216
|
def initialize(message = "Not found", **kwargs)
|
|
217
|
+
kwargs[:code] = "not_found" unless kwargs.key?(:code)
|
|
202
218
|
super(message, status: 404, **kwargs)
|
|
203
219
|
end
|
|
204
220
|
end
|
|
@@ -206,6 +222,7 @@ module RunApi
|
|
|
206
222
|
# Raised when request validation fails (HTTP 400, 422).
|
|
207
223
|
class ValidationError < Error
|
|
208
224
|
def initialize(message = "Validation failed", **kwargs)
|
|
225
|
+
kwargs[:code] = "validation" unless kwargs.key?(:code)
|
|
209
226
|
super
|
|
210
227
|
end
|
|
211
228
|
end
|
|
@@ -213,6 +230,7 @@ module RunApi
|
|
|
213
230
|
# Raised when service is temporarily unavailable (HTTP 503).
|
|
214
231
|
class ServiceUnavailableError < Error
|
|
215
232
|
def initialize(message = "Service unavailable", **kwargs)
|
|
233
|
+
kwargs[:code] = "service_unavailable" unless kwargs.key?(:code)
|
|
216
234
|
super(message, status: kwargs.delete(:status) || 503, **kwargs)
|
|
217
235
|
end
|
|
218
236
|
end
|
|
@@ -220,6 +238,7 @@ module RunApi
|
|
|
220
238
|
# Raised when network connection fails or request cannot be sent.
|
|
221
239
|
class NetworkError < Error
|
|
222
240
|
def initialize(message = "Network error", **kwargs)
|
|
241
|
+
kwargs[:code] = "network" unless kwargs.key?(:code)
|
|
223
242
|
super
|
|
224
243
|
end
|
|
225
244
|
end
|
|
@@ -227,6 +246,7 @@ module RunApi
|
|
|
227
246
|
# Raised when HTTP request exceeds configured timeout.
|
|
228
247
|
class TimeoutError < Error
|
|
229
248
|
def initialize(message = "Request timed out", **kwargs)
|
|
249
|
+
kwargs[:code] = "timeout" unless kwargs.key?(:code)
|
|
230
250
|
super
|
|
231
251
|
end
|
|
232
252
|
end
|
|
@@ -234,6 +254,7 @@ module RunApi
|
|
|
234
254
|
# Raised when polling for task completion exceeds maximum wait time.
|
|
235
255
|
class TaskTimeoutError < Error
|
|
236
256
|
def initialize(message = "Task polling timed out", **kwargs)
|
|
257
|
+
kwargs[:code] = "task_timeout" unless kwargs.key?(:code)
|
|
237
258
|
super
|
|
238
259
|
end
|
|
239
260
|
end
|
|
@@ -241,6 +262,7 @@ module RunApi
|
|
|
241
262
|
# Raised when async task fails during processing.
|
|
242
263
|
class TaskFailedError < Error
|
|
243
264
|
def initialize(message = "Task failed", **kwargs)
|
|
265
|
+
kwargs[:code] = "task_failed" unless kwargs.key?(:code)
|
|
244
266
|
super
|
|
245
267
|
end
|
|
246
268
|
end
|
|
@@ -248,6 +270,7 @@ module RunApi
|
|
|
248
270
|
# Raised when request conflicts with current resource state (HTTP 409).
|
|
249
271
|
class ConflictError < Error
|
|
250
272
|
def initialize(message = "Conflict", **kwargs)
|
|
273
|
+
kwargs[:code] = "conflict" unless kwargs.key?(:code)
|
|
251
274
|
super(message, status: 409, **kwargs)
|
|
252
275
|
end
|
|
253
276
|
end
|
|
@@ -255,6 +278,7 @@ module RunApi
|
|
|
255
278
|
# Raised when server encounters an internal error (HTTP 5xx).
|
|
256
279
|
class ServerError < Error
|
|
257
280
|
def initialize(message = "Server error", **kwargs)
|
|
281
|
+
kwargs[:code] = "server" unless kwargs.key?(:code)
|
|
258
282
|
super(message, status: kwargs.delete(:status) || 500, **kwargs)
|
|
259
283
|
end
|
|
260
284
|
end
|
data/lib/runapi/core/version.rb
CHANGED