Skip to content

Commit

Permalink
feat: proper error messages for lndhub
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanjoshi914 committed Jul 2, 2024
1 parent 5b0b35e commit 91a051b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/extension/background-script/connectors/lndhub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}

Expand Down

0 comments on commit 91a051b

Please sign in to comment.