Skip to content

Commit

Permalink
chore: remove error origin
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisduma-ledger committed Sep 18, 2024
1 parent 5de9455 commit 422b145
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
10 changes: 2 additions & 8 deletions lib/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export enum ErrorOrigin {
"sell",
"swap",
"fund",
}

export class ExchangeError extends Error {
cause: {
swapCode: string;
Expand Down Expand Up @@ -43,8 +37,8 @@ export class PayloadStepError extends ExchangeError {
}

export class SignatureStepError extends ExchangeError {
constructor(origin: ErrorOrigin, nestedError?: Error) {
super(`${origin}003`, nestedError);
constructor(nestedError?: Error) {
super(`swap003`, nestedError);
this.name = "SignatureStepError";
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/handleErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export function handleErrors(walletAPI: WalletAPIClient<any>, error: any) {
const { message, cause } = error as {
message: string;
cause: {
swapCode: string; name: string; message: string
};
swapCode: string;
name: string;
message: string;
};
};

const ignoredErrorNames = new Set([
Expand All @@ -22,16 +24,14 @@ export function handleErrors(walletAPI: WalletAPIClient<any>, error: any) {
"WrongDeviceForAccountRefund",
]);

const ignoredMessages = new Set([
"User refused"
]);
const ignoredMessages = new Set(["User refused"]);

if (ignoredMessages.has(message) || ignoredErrorNames.has(cause.name)) {
throw { ...error, handled: true }; // retry ready
}

// Log and throw to Ledger Live if not ignored
if (error instanceof ExchangeError && cause && cause.swapCode !== "swap003") {
if (error instanceof ExchangeError && cause) {
walletAPI.custom.exchange.throwExchangeErrorToLedgerLive({ error });
}

Expand Down
5 changes: 2 additions & 3 deletions lib/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
NotEnoughFunds,
PayloadStepError,
SignatureStepError,
ErrorOrigin,
} from "./error";
import { handleErrors } from "./handleErrors";
import { Logger } from "./log";
Expand Down Expand Up @@ -271,7 +270,7 @@ export class ExchangeSDK {
throw error;
}

const err = new SignatureStepError(ErrorOrigin.swap, error);
const err = new SignatureStepError(error);
this.handleError(err);
throw err;
});
Expand Down Expand Up @@ -380,7 +379,7 @@ export class ExchangeSDK {
feeStrategy,
})
.catch((error: Error) => {
const err = new SignatureStepError(ErrorOrigin.sell, error);
const err = new SignatureStepError(error);
this.logger.error(err);
throw err;
});
Expand Down

0 comments on commit 422b145

Please sign in to comment.