From 91a051b099a899ffb109aa6361bdcdf01715de40 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Tue, 2 Jul 2024 13:47:29 +0530 Subject: [PATCH] feat: proper error messages for lndhub --- .../background-script/connectors/lndhub.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index 892010534a..0286a61a17 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -418,11 +418,17 @@ export default class LndHub implements Connector { return authData; } catch (e) { - throw new Error( - `API error (${this.config.url})${ - e instanceof Error ? `: ${e.message}` : "" - }` - ); + let error = ""; + if (axios.isAxiosError(e)) { + const data = e.response?.data as + | { reason?: string; message?: string } + | undefined; + error = data?.reason || data?.message || e.message; + } else if (e instanceof Error) { + error = e.message; + } + + throw new Error(`API error (${this.config.url}) ${error}`); } }