@silentswap/sdk 0.1.43 → 0.1.45
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/bridge.js +19 -2
- package/dist/quote-utils.js +12 -0
- package/package.json +1 -1
package/dist/bridge.js
CHANGED
|
@@ -255,7 +255,12 @@ export async function fetchRelayQuote(params, signal) {
|
|
|
255
255
|
const text = await response.text();
|
|
256
256
|
throw parseQuoteApiErrorResponse(response.status, text);
|
|
257
257
|
}
|
|
258
|
-
|
|
258
|
+
const data = await response.json();
|
|
259
|
+
// Some relay.link endpoints return HTTP 200 with error payloads
|
|
260
|
+
if (data && data.errorCode) {
|
|
261
|
+
throw parseQuoteApiErrorResponse(200, JSON.stringify(data));
|
|
262
|
+
}
|
|
263
|
+
return data;
|
|
259
264
|
}
|
|
260
265
|
/**
|
|
261
266
|
* Parse quote API error response (relay.link or deBridge) and return a user-friendly Error.
|
|
@@ -753,12 +758,24 @@ forceProvider) {
|
|
|
753
758
|
// Extract results
|
|
754
759
|
const relayData = relayResult.status === 'fulfilled' ? relayResult.value : null;
|
|
755
760
|
const debridgeData = debridgeResult.status === 'fulfilled' ? debridgeResult.value : null;
|
|
756
|
-
// Both failed
|
|
761
|
+
// Both failed — surface the most relevant inner error message
|
|
757
762
|
if (!relayData && !debridgeData) {
|
|
758
763
|
const errors = [
|
|
759
764
|
relayResult.status === 'rejected' ? relayResult.reason : null,
|
|
760
765
|
debridgeResult.status === 'rejected' ? debridgeResult.reason : null,
|
|
761
766
|
].filter(Boolean);
|
|
767
|
+
// Check inner errors for user-actionable messages before throwing generic AggregateError
|
|
768
|
+
for (const err of errors) {
|
|
769
|
+
if (err instanceof Error) {
|
|
770
|
+
const msg = err.message.toLowerCase();
|
|
771
|
+
if (msg.includes('insufficient funds') || msg.includes('insufficient_funds')) {
|
|
772
|
+
throw new Error('Insufficient funds');
|
|
773
|
+
}
|
|
774
|
+
if (msg.includes('no routes found') || msg.includes('no_swap_routes_found')) {
|
|
775
|
+
throw new Error('No quotes found, try to change input amount');
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
762
779
|
throw new AggregateError(errors, 'All bridge providers failed');
|
|
763
780
|
}
|
|
764
781
|
// Only one succeeded
|
package/dist/quote-utils.js
CHANGED
|
@@ -158,6 +158,18 @@ function getQuoteProviderErrorMessage(relayRejection, debridgeRejection) {
|
|
|
158
158
|
if (check(relayRejection) || check(debridgeRejection)) {
|
|
159
159
|
return 'Insufficient funds';
|
|
160
160
|
}
|
|
161
|
+
const checkNoRoutes = (reason) => {
|
|
162
|
+
if (reason instanceof Error) {
|
|
163
|
+
const msg = reason.message.toLowerCase();
|
|
164
|
+
if (msg.includes('no routes found') || msg.includes('no_swap_routes_found')) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
};
|
|
170
|
+
if (checkNoRoutes(relayRejection) || checkNoRoutes(debridgeRejection)) {
|
|
171
|
+
return 'No quotes found, try to change input amount';
|
|
172
|
+
}
|
|
161
173
|
return 'All quote providers failed';
|
|
162
174
|
}
|
|
163
175
|
/**
|