ton-provider-system 0.1.7 → 0.1.8
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/dist/index.cjs +48 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -947,14 +947,23 @@ var HealthChecker = class {
|
|
|
947
947
|
markDegraded(providerId, network, error) {
|
|
948
948
|
const key = this.getResultKey(providerId, network);
|
|
949
949
|
const existing = this.results.get(key);
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
950
|
+
const result = existing ? {
|
|
951
|
+
...existing,
|
|
952
|
+
status: "degraded",
|
|
953
|
+
error: error || "Marked as degraded",
|
|
954
|
+
lastTested: /* @__PURE__ */ new Date()
|
|
955
|
+
} : {
|
|
956
|
+
id: providerId,
|
|
957
|
+
network,
|
|
958
|
+
success: false,
|
|
959
|
+
status: "degraded",
|
|
960
|
+
latencyMs: null,
|
|
961
|
+
seqno: null,
|
|
962
|
+
blocksBehind: 0,
|
|
963
|
+
lastTested: /* @__PURE__ */ new Date(),
|
|
964
|
+
error: error || "Marked as degraded"
|
|
965
|
+
};
|
|
966
|
+
this.results.set(key, result);
|
|
958
967
|
}
|
|
959
968
|
/**
|
|
960
969
|
* Mark a provider as offline
|
|
@@ -962,14 +971,25 @@ var HealthChecker = class {
|
|
|
962
971
|
markOffline(providerId, network, error) {
|
|
963
972
|
const key = this.getResultKey(providerId, network);
|
|
964
973
|
const existing = this.results.get(key);
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
}
|
|
974
|
+
const result = existing ? {
|
|
975
|
+
...existing,
|
|
976
|
+
status: "offline",
|
|
977
|
+
success: false,
|
|
978
|
+
// Ensure success is false for offline providers
|
|
979
|
+
error: error || "Marked as offline",
|
|
980
|
+
lastTested: /* @__PURE__ */ new Date()
|
|
981
|
+
} : {
|
|
982
|
+
id: providerId,
|
|
983
|
+
network,
|
|
984
|
+
success: false,
|
|
985
|
+
status: "offline",
|
|
986
|
+
latencyMs: null,
|
|
987
|
+
seqno: null,
|
|
988
|
+
blocksBehind: 0,
|
|
989
|
+
lastTested: /* @__PURE__ */ new Date(),
|
|
990
|
+
error: error || "Marked as offline"
|
|
991
|
+
};
|
|
992
|
+
this.results.set(key, result);
|
|
973
993
|
}
|
|
974
994
|
// ========================================================================
|
|
975
995
|
// Private Methods
|
|
@@ -2092,12 +2112,22 @@ var _ProviderManager = class _ProviderManager {
|
|
|
2092
2112
|
if (!this.initialized || !this.network) return;
|
|
2093
2113
|
const provider = this.selector.getBestProvider(this.network);
|
|
2094
2114
|
if (!provider) return;
|
|
2095
|
-
const errorMsg = error instanceof Error ? error.message : error;
|
|
2096
|
-
|
|
2115
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
2116
|
+
const errorMsgLower = errorMsg.toLowerCase();
|
|
2117
|
+
const is429 = errorMsgLower.includes("429") || errorMsgLower.includes("rate limit");
|
|
2118
|
+
const is503 = errorMsgLower.includes("503") || errorMsgLower.includes("service unavailable");
|
|
2119
|
+
const is502 = errorMsgLower.includes("502") || errorMsgLower.includes("bad gateway");
|
|
2120
|
+
const is404 = errorMsgLower.includes("404") || errorMsgLower.includes("not found");
|
|
2121
|
+
const isTimeout = errorMsgLower.includes("timeout") || errorMsgLower.includes("abort");
|
|
2122
|
+
if (isRateLimitError(error) || is429) {
|
|
2097
2123
|
this.rateLimiter.reportRateLimitError(provider.id);
|
|
2098
2124
|
this.healthChecker.markDegraded(provider.id, this.network, errorMsg);
|
|
2125
|
+
} else if (is503 || is502 || is404 || isTimeout) {
|
|
2126
|
+
this.rateLimiter.reportError(provider.id);
|
|
2127
|
+
this.healthChecker.markOffline(provider.id, this.network, errorMsg);
|
|
2099
2128
|
} else {
|
|
2100
2129
|
this.rateLimiter.reportError(provider.id);
|
|
2130
|
+
this.healthChecker.markDegraded(provider.id, this.network, errorMsg);
|
|
2101
2131
|
}
|
|
2102
2132
|
this.selector.handleProviderFailure(provider.id, this.network);
|
|
2103
2133
|
this.notifyListeners();
|