From 654998ad79287a8fbb2e3838038600fe596dc13b Mon Sep 17 00:00:00 2001 From: iain nash Date: Sun, 22 Oct 2023 12:37:02 -0400 Subject: [PATCH] update api --- packages/premint-sdk/src/premint-api.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/premint-sdk/src/premint-api.ts b/packages/premint-sdk/src/premint-api.ts index 8f074bbda..39c9fc51e 100644 --- a/packages/premint-sdk/src/premint-api.ts +++ b/packages/premint-sdk/src/premint-api.ts @@ -59,10 +59,12 @@ export const networkConfigByChain: Record = { export class BadResponse extends Error { status: number; - constructor(message: string, status: number) { + json: any; + constructor(message: string, status: number, json: any) { super(message); this.name = "BadResponse"; this.status = status; + this.json = json; } } @@ -227,7 +229,15 @@ export class PremintAPI { async get(path: string) { const response = await fetch(path, { method: "GET" }); if (response.status !== 200) { - throw new Error(`Invalid response, status ${response.status}`); + let json; + try { + json = await response.json(); + } catch (e: any) {} + throw new BadResponse( + `Invalid response, status ${response.status}`, + response.status, + json, + ); } return await response.json(); } @@ -251,7 +261,15 @@ export class PremintAPI { body: JSON.stringify(data), }); if (response.status !== 200) { - throw new Error(`Bad response: ${response.status}`); + let json; + try { + json = await response.json(); + } catch (e: any) {} + throw new BadResponse( + `Bad response: ${response.status}`, + response.status, + json, + ); } return await response.json(); }