@uipath/common 1.203.0-preview.212 → 1.204.0-preview.211

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.
@@ -0,0 +1,760 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true,
11
+ configurable: true,
12
+ set: __exportSetter.bind(all, name)
13
+ });
14
+ };
15
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
+
17
+ // src/telemetry/pseudonymize.ts
18
+ var SHA256_K = new Uint32Array([
19
+ 1116352408,
20
+ 1899447441,
21
+ 3049323471,
22
+ 3921009573,
23
+ 961987163,
24
+ 1508970993,
25
+ 2453635748,
26
+ 2870763221,
27
+ 3624381080,
28
+ 310598401,
29
+ 607225278,
30
+ 1426881987,
31
+ 1925078388,
32
+ 2162078206,
33
+ 2614888103,
34
+ 3248222580,
35
+ 3835390401,
36
+ 4022224774,
37
+ 264347078,
38
+ 604807628,
39
+ 770255983,
40
+ 1249150122,
41
+ 1555081692,
42
+ 1996064986,
43
+ 2554220882,
44
+ 2821834349,
45
+ 2952996808,
46
+ 3210313671,
47
+ 3336571891,
48
+ 3584528711,
49
+ 113926993,
50
+ 338241895,
51
+ 666307205,
52
+ 773529912,
53
+ 1294757372,
54
+ 1396182291,
55
+ 1695183700,
56
+ 1986661051,
57
+ 2177026350,
58
+ 2456956037,
59
+ 2730485921,
60
+ 2820302411,
61
+ 3259730800,
62
+ 3345764771,
63
+ 3516065817,
64
+ 3600352804,
65
+ 4094571909,
66
+ 275423344,
67
+ 430227734,
68
+ 506948616,
69
+ 659060556,
70
+ 883997877,
71
+ 958139571,
72
+ 1322822218,
73
+ 1537002063,
74
+ 1747873779,
75
+ 1955562222,
76
+ 2024104815,
77
+ 2227730452,
78
+ 2361852424,
79
+ 2428436474,
80
+ 2756734187,
81
+ 3204031479,
82
+ 3329325298
83
+ ]);
84
+ var SHA256_INITIAL_STATE = new Uint32Array([
85
+ 1779033703,
86
+ 3144134277,
87
+ 1013904242,
88
+ 2773480762,
89
+ 1359893119,
90
+ 2600822924,
91
+ 528734635,
92
+ 1541459225
93
+ ]);
94
+
95
+ // src/singleton.ts
96
+ var PREFIX = "@uipath/common/";
97
+ var _g = globalThis;
98
+ function singleton(ctorOrName) {
99
+ const name = typeof ctorOrName === "string" ? ctorOrName : ctorOrName.name;
100
+ const key = Symbol.for(PREFIX + name);
101
+ return {
102
+ get(fallback) {
103
+ return _g[key] ?? fallback;
104
+ },
105
+ set(value) {
106
+ _g[key] = value;
107
+ },
108
+ clear() {
109
+ delete _g[key];
110
+ },
111
+ getOrInit(factory, guard) {
112
+ const existing = _g[key];
113
+ if (existing != null && typeof existing === "object") {
114
+ if (!guard || guard(existing)) {
115
+ return existing;
116
+ }
117
+ }
118
+ const instance = factory();
119
+ _g[key] = instance;
120
+ return instance;
121
+ }
122
+ };
123
+ }
124
+
125
+ // src/telemetry/supplied-values.ts
126
+ var suppliedValuesSlot = singleton("TelemetrySuppliedArgumentValues");
127
+
128
+ // src/telemetry/pii-redactor.ts
129
+ var SENSITIVE_NAME_TOKENS = new Set([
130
+ "token",
131
+ "tokens",
132
+ "secret",
133
+ "secrets",
134
+ "password",
135
+ "passwords",
136
+ "pwd",
137
+ "credential",
138
+ "credentials",
139
+ "auth",
140
+ "authentication",
141
+ "authorization",
142
+ "authority",
143
+ "cert",
144
+ "certificate",
145
+ "certificates"
146
+ ]);
147
+ var SENSITIVE_KEY_PREFIXES = new Set([
148
+ "api",
149
+ "access",
150
+ "client",
151
+ "private",
152
+ "public",
153
+ "signing",
154
+ "encryption",
155
+ "session",
156
+ "master",
157
+ "shared",
158
+ "root",
159
+ "ssh",
160
+ "rsa",
161
+ "aes",
162
+ "hmac",
163
+ "oauth"
164
+ ]);
165
+ var SOURCE_FILE_EXTENSIONS = new Set([
166
+ "ts",
167
+ "tsx",
168
+ "js",
169
+ "jsx",
170
+ "mjs",
171
+ "cjs",
172
+ "cts",
173
+ "mts",
174
+ "py",
175
+ "cs",
176
+ "java",
177
+ "go",
178
+ "rs",
179
+ "rb",
180
+ "php",
181
+ "sh",
182
+ "ps1",
183
+ "json",
184
+ "jsonc",
185
+ "yaml",
186
+ "yml",
187
+ "xml",
188
+ "xaml",
189
+ "md",
190
+ "txt",
191
+ "log",
192
+ "css",
193
+ "html",
194
+ "htm",
195
+ "csproj",
196
+ "nuspec",
197
+ "sql"
198
+ ]);
199
+ var QUOTED_LITERAL_MAX_SPAN = 200;
200
+ var QUOTED_LITERAL_PATTERN = new RegExp([
201
+ `(?<![A-Za-z0-9])'(?:[^\\
202
+ ]|\\.){2,${QUOTED_LITERAL_MAX_SPAN}}?'(?![A-Za-z0-9])`,
203
+ `(?<![A-Za-z0-9])"(?:[^\\
204
+ ]|\\.){2,${QUOTED_LITERAL_MAX_SPAN}}?"(?![A-Za-z0-9])`
205
+ ].join("|"), "g");
206
+ var MESSAGE_NAMES = new Set([
207
+ "message",
208
+ "errormessage",
209
+ "errmessage",
210
+ "error_message",
211
+ "msg",
212
+ "detail",
213
+ "details",
214
+ "reason",
215
+ "instructions",
216
+ "warning"
217
+ ]);
218
+ function nameTokens(name) {
219
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s._-]+/).map((t) => t.toLowerCase()).filter(Boolean);
220
+ }
221
+ function isSensitiveName(name) {
222
+ const tokens = nameTokens(name);
223
+ for (let i = 0;i < tokens.length; i++) {
224
+ const token = tokens[i];
225
+ if (SENSITIVE_NAME_TOKENS.has(token)) {
226
+ return true;
227
+ }
228
+ if (token === "key" || token === "keys") {
229
+ const prev = tokens[i - 1];
230
+ if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
231
+ return true;
232
+ }
233
+ }
234
+ }
235
+ return false;
236
+ }
237
+
238
+ // src/catch-error.ts
239
+ var MAX_SERIALIZED_LENGTH = 500;
240
+ var TRUNCATION_SUFFIX = "…(truncated)";
241
+ var REDACTED = "[REDACTED]";
242
+ function cap(text) {
243
+ return text.length > MAX_SERIALIZED_LENGTH ? `${text.slice(0, MAX_SERIALIZED_LENGTH)}${TRUNCATION_SUFFIX}` : text;
244
+ }
245
+ function omitSensitive(key, value) {
246
+ return key.length > 0 && isSensitiveName(key) ? REDACTED : value;
247
+ }
248
+ function describeThrownValue(value) {
249
+ if (typeof value !== "object" || value === null) {
250
+ return String(value);
251
+ }
252
+ let message;
253
+ try {
254
+ message = value.message;
255
+ } catch {
256
+ message = undefined;
257
+ }
258
+ if (typeof message === "string" && message.length > 0) {
259
+ return cap(message);
260
+ }
261
+ try {
262
+ const json = JSON.stringify(value, omitSensitive);
263
+ if (json !== undefined) {
264
+ return cap(json);
265
+ }
266
+ } catch {}
267
+ return String(value);
268
+ }
269
+ function toError(error) {
270
+ return error instanceof Error ? error : new Error(describeThrownValue(error), { cause: error });
271
+ }
272
+ function isPromiseLike(value) {
273
+ return value !== null && typeof value === "object" && typeof value.then === "function";
274
+ }
275
+ function catchError(fnOrPromise) {
276
+ if (isPromiseLike(fnOrPromise)) {
277
+ return settlePromiseLike(fnOrPromise);
278
+ }
279
+ try {
280
+ const result = fnOrPromise();
281
+ if (isPromiseLike(result)) {
282
+ return settlePromiseLike(result);
283
+ }
284
+ return [undefined, result];
285
+ } catch (error) {
286
+ return [toError(error), undefined];
287
+ }
288
+ }
289
+ function settlePromiseLike(thenable) {
290
+ return Promise.resolve(thenable).then((data) => [undefined, data]).catch((error) => [toError(error), undefined]);
291
+ }
292
+
293
+ // src/error-graph.ts
294
+ function* walkErrorGraph(error) {
295
+ const queue = [error];
296
+ const seen = new Set;
297
+ for (let steps = 0;queue.length > 0 && steps < 32; steps++) {
298
+ const current = queue.shift();
299
+ if (current === null || typeof current !== "object")
300
+ continue;
301
+ if (seen.has(current))
302
+ continue;
303
+ seen.add(current);
304
+ const cur = current;
305
+ yield cur;
306
+ if (cur.cause !== undefined)
307
+ queue.push(cur.cause);
308
+ if (Array.isArray(cur.errors))
309
+ queue.push(...cur.errors);
310
+ }
311
+ return;
312
+ }
313
+ function parseHttpStatusFromMessage(message) {
314
+ const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
315
+ if (!match)
316
+ return;
317
+ const status = Number(match[1]);
318
+ return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
319
+ }
320
+ function findHttpStatusInGraph(error) {
321
+ for (const node of walkErrorGraph(error)) {
322
+ const response = node.response;
323
+ const explicit = typeof node.status === "number" ? node.status : response?.status;
324
+ if (typeof explicit === "number" && explicit >= 400 && explicit <= 599) {
325
+ return explicit;
326
+ }
327
+ if (typeof node.message === "string") {
328
+ const parsed = parseHttpStatusFromMessage(node.message);
329
+ if (parsed !== undefined && parsed >= 400) {
330
+ return parsed;
331
+ }
332
+ }
333
+ }
334
+ return;
335
+ }
336
+
337
+ // src/local-permission-codes.ts
338
+ var LOCAL_PERMISSION_ERROR_CODES = new Set([
339
+ "EACCES",
340
+ "EPERM",
341
+ "EROFS"
342
+ ]);
343
+
344
+ // src/error-handler.ts
345
+ var DEFAULT_401 = "Unauthorized (401). The session is missing or expired, or its token carries no scope for this API. Run `uip login status --detailed` to see the session and its scopes.";
346
+ var DEFAULT_403 = "Forbidden (403). The account lacks permission for this operation, or the token carries no scope for this API. Run `uip login status --detailed` to see the token's scopes.";
347
+ var DEFAULT_405 = "Method Not Allowed (405). The endpoint may not exist or the base URL may be incorrect.";
348
+ var DEFAULT_413 = "Payload too large (413). The upload exceeded the server or CDN size limit. Reduce the package size — for example, exclude unused dependencies or remove large files from the project — and try again.";
349
+ var HTML_RESPONSE_MESSAGE = "Received HTML instead of the expected JSON response.";
350
+ var NETWORK_ERROR_CODES = new Set([
351
+ "ECONNREFUSED",
352
+ "ECONNRESET",
353
+ "ENOTFOUND",
354
+ "EAI_AGAIN",
355
+ "ETIMEDOUT",
356
+ "EPIPE",
357
+ "EHOSTUNREACH",
358
+ "ENETUNREACH",
359
+ "EAI_FAIL"
360
+ ]);
361
+ var TLS_ERROR_CODES = new Set([
362
+ "SELF_SIGNED_CERT_IN_CHAIN",
363
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
364
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
365
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
366
+ "UNABLE_TO_GET_ISSUER_CERT",
367
+ "CERT_HAS_EXPIRED",
368
+ "CERT_UNTRUSTED",
369
+ "ERR_TLS_CERT_ALTNAME_INVALID"
370
+ ]);
371
+ var TLS_INSTRUCTIONS = "The server's TLS certificate could not be verified. Most often a " + "corporate proxy/firewall re-signs HTTPS with a root CA that Node does " + "not trust — set NODE_EXTRA_CA_CERTS to that CA's PEM file (and HTTPS_PROXY " + "if you connect through a proxy). If the certificate is instead expired or " + "its hostname does not match, fix the endpoint URL or the system clock. " + "Then retry.";
372
+ var NETWORK_INSTRUCTIONS = "Could not reach the UiPath service. Check your network connection and " + "VPN, confirm any HTTP_PROXY/HTTPS_PROXY/NO_PROXY settings are correct, " + "then retry.";
373
+ var LOCAL_PERMISSION_MESSAGE_PATTERN = new RegExp(`\\b(${[...LOCAL_PERMISSION_ERROR_CODES].join("|")})\\b`);
374
+ function localPermissionInstructions(code, path) {
375
+ const target = path !== undefined ? `'${path}'` : "a local file or resource";
376
+ if (code === "EROFS") {
377
+ return `The filesystem containing ${target} is read-only (EROFS), so the ` + "CLI could not write to it. This is a local environment problem, " + "not a UiPath service error — retrying will not help. Use a " + "writable location, or give this environment write access to the " + "path.";
378
+ }
379
+ const onWindows = typeof process !== "undefined" && process.platform === "win32";
380
+ const remedy = onWindows ? "Re-run from an elevated terminal, close any program holding " + "the file open, or grant your user access to the path." : "Grant this user (or the sandbox the command runs in) access " + "to the path, or run the command outside the sandbox.";
381
+ return `The operating system denied access to ${target} (${code}). This is ` + "a local permission problem, not a UiPath service error — retrying " + `without a permission change will not help. ${remedy}`;
382
+ }
383
+ function carriedInstructions(error) {
384
+ if (!error || typeof error !== "object")
385
+ return;
386
+ const e = error;
387
+ return typeof e.instructions === "string" ? e.instructions : undefined;
388
+ }
389
+ function formatErrorChain(error) {
390
+ const lines = [];
391
+ const seen = new Set;
392
+ const visit = (value, depth) => {
393
+ if (lines.length >= 32)
394
+ return;
395
+ const indent = " ".repeat(depth);
396
+ if (value === null || typeof value !== "object") {
397
+ lines.push(`${indent}${String(value)}`);
398
+ return;
399
+ }
400
+ if (seen.has(value))
401
+ return;
402
+ seen.add(value);
403
+ const cur = value;
404
+ const name = typeof cur.name === "string" ? cur.name : "Error";
405
+ const message = typeof cur.message === "string" ? cur.message : String(value);
406
+ const code = typeof cur.code === "string" ? ` [${cur.code}]` : "";
407
+ lines.push(`${indent}${name}: ${message}${code}`);
408
+ if (cur.cause !== undefined)
409
+ visit(cur.cause, depth + 1);
410
+ if (Array.isArray(cur.errors)) {
411
+ for (const nested of cur.errors) {
412
+ visit(nested, depth + 1);
413
+ }
414
+ }
415
+ };
416
+ visit(error, 0);
417
+ return lines.join(`
418
+ `);
419
+ }
420
+ function describeConnectivityError(error) {
421
+ for (const cur of walkErrorGraph(error)) {
422
+ const code = typeof cur.code === "string" ? cur.code : undefined;
423
+ const message = typeof cur.message === "string" ? cur.message : undefined;
424
+ if (code && TLS_ERROR_CODES.has(code)) {
425
+ return {
426
+ code,
427
+ kind: "tls",
428
+ message: message ?? code,
429
+ instructions: TLS_INSTRUCTIONS
430
+ };
431
+ }
432
+ if (code && NETWORK_ERROR_CODES.has(code)) {
433
+ return {
434
+ code,
435
+ kind: "network",
436
+ message: message ?? code,
437
+ instructions: NETWORK_INSTRUCTIONS
438
+ };
439
+ }
440
+ }
441
+ return;
442
+ }
443
+ function describePermissionError(error) {
444
+ for (const cur of walkErrorGraph(error)) {
445
+ const message = typeof cur.message === "string" ? cur.message : undefined;
446
+ const code = matchLocalPermissionCode(cur.code, message);
447
+ if (!code)
448
+ continue;
449
+ const path = localPermissionPath(cur.path, message);
450
+ return {
451
+ code,
452
+ message: message ?? code,
453
+ ...path !== undefined ? { path } : {},
454
+ instructions: localPermissionInstructions(code, path)
455
+ };
456
+ }
457
+ return;
458
+ }
459
+ function matchLocalPermissionCode(code, message) {
460
+ if (typeof code === "string" && LOCAL_PERMISSION_ERROR_CODES.has(code)) {
461
+ return code;
462
+ }
463
+ const match = message ? LOCAL_PERMISSION_MESSAGE_PATTERN.exec(message) : null;
464
+ return match ? match[1] : undefined;
465
+ }
466
+ function localPermissionPath(path, message) {
467
+ if (typeof path === "string")
468
+ return path;
469
+ return message ? /'([^']+)'/.exec(message)?.[1] : undefined;
470
+ }
471
+ function isHtmlDocument(body) {
472
+ return /^\s*(<!doctype html|<html\b)/i.test(body);
473
+ }
474
+ function retryHintForRetryAfter(seconds) {
475
+ if (seconds <= 1) {
476
+ return "RetryAfter1Second";
477
+ }
478
+ if (seconds <= 10) {
479
+ return "RetryAfter10Seconds";
480
+ }
481
+ if (seconds <= 30) {
482
+ return "RetryAfter30Seconds";
483
+ }
484
+ return "RetryAfter60Seconds";
485
+ }
486
+ function classifyError(status, error) {
487
+ if (status === 400 || status === 409 || status === 422) {
488
+ return { errorCode: "invalid_argument", retry: "RetryWillNotFix" };
489
+ }
490
+ if (status === 401) {
491
+ return {
492
+ errorCode: "authentication_required",
493
+ retry: "RetryWillNotFix"
494
+ };
495
+ }
496
+ if (status === 403) {
497
+ return { errorCode: "permission_denied", retry: "RetryWillNotFix" };
498
+ }
499
+ if (status === 404) {
500
+ return { errorCode: "not_found", retry: "RetryWillNotFix" };
501
+ }
502
+ if (status === 405) {
503
+ return { errorCode: "method_not_allowed", retry: "RetryWillNotFix" };
504
+ }
505
+ if (status === 413) {
506
+ return { errorCode: "invalid_argument", retry: "RetryWillNotFix" };
507
+ }
508
+ if (status === 408) {
509
+ return { errorCode: "timeout", retry: "RetryLater" };
510
+ }
511
+ if (status === 429) {
512
+ return { errorCode: "rate_limited", retry: "RetryLater" };
513
+ }
514
+ if (status !== undefined && status >= 500 && status < 600) {
515
+ return { errorCode: "server_error", retry: "RetryLater" };
516
+ }
517
+ if (status === undefined && describePermissionError(error)) {
518
+ return {
519
+ errorCode: "local_permission_denied",
520
+ retry: "RetryWillNotFix"
521
+ };
522
+ }
523
+ const connectivity = describeConnectivityError(error);
524
+ if (connectivity) {
525
+ return {
526
+ errorCode: "network_error",
527
+ retry: connectivity.kind === "tls" ? "RetryWillNotFix" : "RetryLater"
528
+ };
529
+ }
530
+ return { errorCode: "unknown_error", retry: "RetryWillNotFix" };
531
+ }
532
+ function formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus) {
533
+ if (extractedMessage) {
534
+ return `HTTP ${status}: ${extractedMessage}`;
535
+ }
536
+ return inferredStatus !== undefined ? rawMessage : `HTTP ${status}: ${rawMessage}`;
537
+ }
538
+ async function extractErrorDetails(error, options) {
539
+ const err = error !== null && error !== undefined && typeof error === "object" ? error : {};
540
+ const response = err.response;
541
+ const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
542
+ const explicitStatus = err.status ?? response?.status;
543
+ const inferredStatus = explicitStatus === undefined ? parseHttpStatusFromMessage(rawMessage) : undefined;
544
+ const status = explicitStatus ?? inferredStatus;
545
+ const isSuccessfulResponse = status !== undefined && status >= 200 && status < 300;
546
+ let rawBody;
547
+ let extractedMessage;
548
+ let parsedBody;
549
+ const textFn = response?.text?.bind(response);
550
+ if (textFn) {
551
+ const [bodyError, body] = await catchError((async () => textFn())());
552
+ if (!bodyError && body) {
553
+ rawBody = body;
554
+ const [parseError, parsed] = catchError(() => JSON.parse(body));
555
+ if (!parseError && parsed && typeof parsed === "object") {
556
+ parsedBody = parsed;
557
+ if (parsedBody.errors && typeof parsedBody.errors === "object") {
558
+ for (const field of Object.values(parsedBody.errors)) {
559
+ if (Array.isArray(field) && field.length > 0) {
560
+ const first = field[0];
561
+ if (first && typeof first.message === "string") {
562
+ extractedMessage = first.message;
563
+ break;
564
+ }
565
+ }
566
+ }
567
+ }
568
+ if (!extractedMessage) {
569
+ extractedMessage = typeof parsedBody.message === "string" ? parsedBody.message : typeof parsedBody.errorMessage === "string" ? parsedBody.errorMessage : typeof parsedBody.title === "string" ? parsedBody.title : undefined;
570
+ }
571
+ if (!extractedMessage) {
572
+ extractedMessage = body;
573
+ }
574
+ if (extractedMessage && typeof parsedBody.detail === "string" && parsedBody.detail.length > 0 && !extractedMessage.includes(parsedBody.detail)) {
575
+ extractedMessage = `${extractedMessage}: ${parsedBody.detail}`;
576
+ }
577
+ } else {
578
+ extractedMessage = isHtmlDocument(body) ? HTML_RESPONSE_MESSAGE : body;
579
+ }
580
+ }
581
+ }
582
+ let message;
583
+ let result = "Failure";
584
+ const classificationStatus = status ?? findHttpStatusInGraph(error);
585
+ const classification = classifyError(classificationStatus, error);
586
+ let retry = classification.retry;
587
+ if (status === 401) {
588
+ message = DEFAULT_401;
589
+ result = "AuthenticationError";
590
+ } else if (status === 403) {
591
+ message = options?.forbiddenMessage ?? DEFAULT_403;
592
+ result = "AuthenticationError";
593
+ } else if (status === 405) {
594
+ message = DEFAULT_405;
595
+ } else if (status === 413) {
596
+ message = DEFAULT_413;
597
+ } else if (status === 400 || status === 422) {
598
+ message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
599
+ result = "ValidationError";
600
+ } else if (status === 429) {
601
+ message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
602
+ } else if (extractedMessage) {
603
+ if (isSuccessfulResponse && rawMessage !== "Unknown error") {
604
+ message = rawMessage;
605
+ } else {
606
+ message = status ? `HTTP ${status}: ${extractedMessage}` : extractedMessage;
607
+ }
608
+ } else if (status) {
609
+ if (inferredStatus !== undefined) {
610
+ message = rawMessage;
611
+ } else if (rawMessage === "Unknown error" && response) {
612
+ const statusText = response.statusText;
613
+ message = statusText ? `HTTP ${status} ${statusText}` : `HTTP ${status} - request failed`;
614
+ } else {
615
+ message = `HTTP ${status}: ${rawMessage}`;
616
+ }
617
+ } else {
618
+ message = rawMessage;
619
+ }
620
+ if (status === undefined) {
621
+ const connectivity = describeConnectivityError(error);
622
+ if (connectivity && connectivity.message !== message && !message.includes(connectivity.message)) {
623
+ message = `${message}: ${connectivity.message}`;
624
+ }
625
+ }
626
+ const permission = status === undefined ? describePermissionError(error) : undefined;
627
+ if (permission) {
628
+ if (permission.message !== message && !message.includes(permission.message)) {
629
+ message = `${message}: ${permission.message}`;
630
+ }
631
+ if (!message.includes(permission.instructions)) {
632
+ const punctuated = message.endsWith(".") ? message : `${message}.`;
633
+ message = `${punctuated} ${permission.instructions}`;
634
+ }
635
+ }
636
+ let details = rawMessage;
637
+ if (rawBody) {
638
+ if (parsedBody) {
639
+ const extra = {};
640
+ if (parsedBody.errorCode)
641
+ extra.errorCode = parsedBody.errorCode;
642
+ if (parsedBody.detail)
643
+ extra.detail = parsedBody.detail;
644
+ if (parsedBody.details)
645
+ extra.details = parsedBody.details;
646
+ if (parsedBody.errors != null)
647
+ extra.errors = parsedBody.errors;
648
+ if (parsedBody.data && typeof parsedBody.data === "object" && Object.keys(parsedBody.data).length > 0) {
649
+ extra.data = parsedBody.data;
650
+ }
651
+ details = Object.keys(extra).length > 0 ? JSON.stringify(extra) : rawBody;
652
+ } else {
653
+ details = rawBody;
654
+ }
655
+ } else if (typeof err.message === "string") {
656
+ details = err.message;
657
+ } else {
658
+ details = describeThrownValue(error);
659
+ }
660
+ const context = {};
661
+ if (classificationStatus) {
662
+ context.httpStatus = classificationStatus;
663
+ }
664
+ if (parsedBody?.errorCode && typeof parsedBody.errorCode === "string") {
665
+ context.errorCode = parsedBody.errorCode;
666
+ } else if (parsedBody?.code && typeof parsedBody.code === "string") {
667
+ context.errorCode = parsedBody.code;
668
+ }
669
+ if (parsedBody?.requestId && typeof parsedBody.requestId === "string") {
670
+ context.requestId = parsedBody.requestId;
671
+ }
672
+ if (parsedBody?.traceId && typeof parsedBody.traceId === "string") {
673
+ context.traceId = parsedBody.traceId;
674
+ }
675
+ if (permission?.path !== undefined) {
676
+ context.path = permission.path;
677
+ }
678
+ if (status === 429) {
679
+ const resp = response;
680
+ const headersObj = resp?.headers;
681
+ let retryAfterValue;
682
+ if (headersObj && typeof headersObj === "object" && typeof headersObj.get === "function") {
683
+ retryAfterValue = headersObj.get("retry-after") ?? undefined;
684
+ }
685
+ if (!retryAfterValue && headersObj && typeof headersObj === "object") {
686
+ const headers = headersObj;
687
+ retryAfterValue = headers["retry-after"] ?? headers["Retry-After"];
688
+ }
689
+ if (retryAfterValue) {
690
+ const seconds = Number(retryAfterValue);
691
+ if (!Number.isNaN(seconds)) {
692
+ context.retryAfter = seconds;
693
+ retry = retryHintForRetryAfter(seconds);
694
+ }
695
+ }
696
+ }
697
+ const hasContext = Object.keys(context).length > 0;
698
+ let parsedErrors;
699
+ if (parsedBody?.errors && typeof parsedBody.errors === "object") {
700
+ const errors = {};
701
+ for (const [field, raw] of Object.entries(parsedBody.errors)) {
702
+ if (Array.isArray(raw)) {
703
+ const messages = raw.map((entry) => {
704
+ if (typeof entry === "string")
705
+ return entry;
706
+ if (entry && typeof entry === "object" && typeof entry.message === "string") {
707
+ return entry.message;
708
+ }
709
+ return String(entry);
710
+ }).filter(Boolean);
711
+ if (messages.length > 0)
712
+ errors[field] = messages;
713
+ } else if (typeof raw === "string") {
714
+ errors[field] = [raw];
715
+ }
716
+ }
717
+ if (Object.keys(errors).length > 0)
718
+ parsedErrors = errors;
719
+ }
720
+ return {
721
+ result,
722
+ errorCode: classification.errorCode,
723
+ message,
724
+ retry,
725
+ details,
726
+ ...hasContext ? { context } : {},
727
+ ...parsedErrors ? { parsedErrors } : {}
728
+ };
729
+ }
730
+ async function extractErrorMessage(error, options) {
731
+ const { message } = await extractErrorDetails(error, options);
732
+ return message;
733
+ }
734
+ function extractErrorMessageSync(error) {
735
+ if (error instanceof Error) {
736
+ return error.message;
737
+ }
738
+ if (typeof error === "object" && error !== null) {
739
+ if ("status" in error && error.status === 401) {
740
+ return DEFAULT_401;
741
+ }
742
+ if ("message" in error && typeof error.message === "string") {
743
+ return error.message;
744
+ }
745
+ }
746
+ return describeThrownValue(error);
747
+ }
748
+ export {
749
+ carriedInstructions,
750
+ describeConnectivityError,
751
+ describePermissionError,
752
+ extractErrorDetails,
753
+ extractErrorMessage,
754
+ extractErrorMessageSync,
755
+ formatErrorChain,
756
+ isHtmlDocument,
757
+ parseHttpStatusFromMessage
758
+ };
759
+
760
+ //# debugId=3365B45717D61F5364756E2164756E21