moralis-cli 0.1.2 → 0.1.3
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.
- package/package.json +1 -1
- package/src/cli.js +65 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moralis-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Use Moralis API via Moralis CLI directly inside AI agents with secure API key handling and access to EVM and Solana blockchain data.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"moralis-cli": "bin/moralis-cli.js"
|
package/src/cli.js
CHANGED
|
@@ -1011,13 +1011,76 @@ async function fetchWithRetry(url, options, retryOptions = {}) {
|
|
|
1011
1011
|
} catch (error) {
|
|
1012
1012
|
lastError = error;
|
|
1013
1013
|
if (attempt >= attempts || !shouldRetryError(error)) {
|
|
1014
|
-
throw error;
|
|
1014
|
+
throw createFetchError(label, error);
|
|
1015
1015
|
}
|
|
1016
1016
|
await sleepWithBackoff(attempt, baseDelayMs);
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
1019
1019
|
|
|
1020
|
-
|
|
1020
|
+
if (lastError) {
|
|
1021
|
+
throw createFetchError(label, lastError);
|
|
1022
|
+
}
|
|
1023
|
+
throw new Error(`${label} failed`);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
function createFetchError(label, error) {
|
|
1027
|
+
const baseMessage = error && error.message ? error.message : String(error);
|
|
1028
|
+
const causeMessages = collectErrorCauseMessages(error);
|
|
1029
|
+
const details = causeMessages.length > 0 ? `; ${causeMessages.join('; ')}` : '';
|
|
1030
|
+
const message = `${label} failed: ${baseMessage}${details}`;
|
|
1031
|
+
|
|
1032
|
+
if (typeof Error === 'function' && error instanceof Error) {
|
|
1033
|
+
return new Error(message, { cause: error });
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
return new Error(message);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
function collectErrorCauseMessages(error) {
|
|
1040
|
+
const messages = [];
|
|
1041
|
+
const seen = new Set();
|
|
1042
|
+
let current = error;
|
|
1043
|
+
let index = 0;
|
|
1044
|
+
|
|
1045
|
+
while (current && typeof current === 'object' && current.cause) {
|
|
1046
|
+
const cause = current.cause;
|
|
1047
|
+
if (!cause || seen.has(cause)) {
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
seen.add(cause);
|
|
1051
|
+
index += 1;
|
|
1052
|
+
messages.push(`cause ${index}: ${formatCauseDetails(cause)}`);
|
|
1053
|
+
current = cause;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
return messages;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function formatCauseDetails(cause) {
|
|
1060
|
+
const message = cause && typeof cause.message === 'string' && cause.message ? cause.message : String(cause);
|
|
1061
|
+
|
|
1062
|
+
if (!cause || typeof cause !== 'object') {
|
|
1063
|
+
return message;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
const extras = [];
|
|
1067
|
+
if (typeof cause.code === 'string' && !message.includes(cause.code)) {
|
|
1068
|
+
extras.push(`code=${cause.code}`);
|
|
1069
|
+
}
|
|
1070
|
+
if (typeof cause.syscall === 'string') {
|
|
1071
|
+
extras.push(`syscall=${cause.syscall}`);
|
|
1072
|
+
}
|
|
1073
|
+
if (typeof cause.hostname === 'string') {
|
|
1074
|
+
extras.push(`hostname=${cause.hostname}`);
|
|
1075
|
+
}
|
|
1076
|
+
if (typeof cause.address === 'string') {
|
|
1077
|
+
extras.push(`address=${cause.address}`);
|
|
1078
|
+
}
|
|
1079
|
+
if (typeof cause.port === 'number') {
|
|
1080
|
+
extras.push(`port=${cause.port}`);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
return extras.length > 0 ? `${message} (${extras.join(', ')})` : message;
|
|
1021
1084
|
}
|
|
1022
1085
|
|
|
1023
1086
|
function shouldRetryResponse(response, attempt, maxAttempts) {
|