Skip to content

Commit 0ca91dc

Browse files
chore: add esplora error handling (#757)
* chore: add esplora error handling * chore: fix gateway error messages
1 parent f995b7a commit 0ca91dc

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

sdk/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gobob/bob-sdk",
3-
"version": "4.2.7",
3+
"version": "4.2.8",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"scripts": {

sdk/src/esplora.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,11 @@ export class EsploraClient {
497497
private async getJson<T>(url: string): Promise<T> {
498498
const response = await fetch(url);
499499
if (!response.ok) {
500-
throw new Error(response.statusText);
500+
const text = await response.text();
501+
const errorText = `Esplora error: ${text}`;
502+
throw new Error(errorText);
501503
}
502-
return (await response.json()) as Promise<T>;
504+
return response.json() as Promise<T>;
503505
}
504506

505507
/**

sdk/src/gateway/client.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,15 @@ export class GatewayApiClient {
248248
if (!response.ok) {
249249
const errorData = await response.json().catch(() => null);
250250
const errorMessage = errorData?.message || 'Failed to get onramp liquidity';
251-
throw new Error(`Onramp liquidity API Error: ${errorMessage}`);
251+
throw new Error(errorMessage);
252252
}
253253

254254
const jsonResponse = await response.json();
255255

256256
if (!jsonResponse.orderDetails) {
257257
const errorData = jsonResponse.errorData;
258258
const apiMessage = errorData?.message;
259-
const errorMessage = apiMessage
260-
? `Failed to get onramp quote: ${apiMessage}`
261-
: 'Failed to get onramp quote';
259+
const errorMessage = apiMessage || 'Failed to get onramp quote';
262260
throw new Error(errorMessage);
263261
}
264262

@@ -310,9 +308,7 @@ export class GatewayApiClient {
310308
if (!response.ok) {
311309
const errorData = await response.json().catch(() => null);
312310
const apiMessage = errorData?.message;
313-
const errorMessage = apiMessage
314-
? `Failed to fetch offramp registry contract: ${apiMessage}`
315-
: 'Failed to fetch offramp registry contract';
311+
const errorMessage = apiMessage || 'Failed to fetch offramp registry contract';
316312
throw new Error(errorMessage);
317313
}
318314
return response.text() as Promise<Address>;
@@ -337,7 +333,7 @@ export class GatewayApiClient {
337333
if (!response.ok) {
338334
const errorData = await response.json().catch(() => null);
339335
const errorMessage = errorData?.message || 'Failed to get offramp liquidity';
340-
throw new Error(`Offramp liquidity API Error: ${errorMessage}`);
336+
throw new Error(errorMessage);
341337
}
342338

343339
const rawLiquidity = await response.json();
@@ -373,9 +369,7 @@ export class GatewayApiClient {
373369
if (!response.ok) {
374370
const errorData = await response.json().catch(() => null);
375371
const apiMessage = errorData?.message;
376-
const errorMessage = apiMessage
377-
? `Failed to get offramp quote: ${apiMessage}`
378-
: `Failed to get offramp quote`;
372+
const errorMessage = apiMessage || `Failed to get offramp quote`;
379373
throw new Error(`${errorMessage} | queryParams: ${queryParams}`);
380374
}
381375

@@ -702,7 +696,7 @@ export class GatewayApiClient {
702696
if (!response.ok) {
703697
const errorData = await response.json().catch(() => null);
704698
const apiMessage = errorData?.message;
705-
const errorMessage = apiMessage ? `Failed to create order: ${apiMessage}` : 'Failed to create order';
699+
const errorMessage = apiMessage || 'Failed to create order';
706700
throw new Error(errorMessage);
707701
}
708702

@@ -931,7 +925,7 @@ export class GatewayApiClient {
931925
if (!response.ok) {
932926
const errorData = await response.json().catch(() => null);
933927
const apiMessage = errorData?.message;
934-
const errorMessage = apiMessage ? `Failed to update order: ${apiMessage}` : `Failed to update order`;
928+
const errorMessage = apiMessage || `Failed to update order`;
935929
throw new Error(errorMessage);
936930
}
937931

@@ -1097,9 +1091,7 @@ export class GatewayApiClient {
10971091
if (!response.ok) {
10981092
const errorData = await response.json().catch(() => null);
10991093
const apiMessage = errorData?.message;
1100-
const errorMessage = apiMessage
1101-
? `Failed to fetch supported token addresses: ${apiMessage}`
1102-
: 'Failed to fetch supported token addresses';
1094+
const errorMessage = apiMessage || 'Failed to fetch supported token addresses';
11031095
throw new Error(errorMessage);
11041096
}
11051097
return response.json();

0 commit comments

Comments
 (0)