diff options
author | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
commit | 5d23eb36354d07508a015531f298b3e261bbafce (patch) | |
tree | fae0d2599c94d88c9264bb63a301adb1706824c1 /packages/taler-wallet-core/src/wallet.ts | |
parent | f8d12f7b0d4af1b1769b89e80c87f9c169678564 (diff) | |
download | wallet-core-5d23eb36354d07508a015531f298b3e261bbafce.tar.xz |
wallet: improve error handling and error codes
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 62 |
1 files changed, 23 insertions, 39 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index bbff465a8..cb8b53adf 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -100,9 +100,8 @@ import { WalletStoresV1, } from "./db.js"; import { - makeErrorDetails, - OperationFailedAndReportedError, - OperationFailedError, + getErrorDetailFromException, + TalerError, } from "./errors.js"; import { exportBackup } from "./operations/backup/export.js"; import { @@ -297,10 +296,10 @@ export async function runPending( try { await processOnePendingOperation(ws, p, forceNow); } catch (e) { - if (e instanceof OperationFailedAndReportedError) { + if (e instanceof TalerError) { console.error( "Operation failed:", - JSON.stringify(e.operationError, undefined, 2), + JSON.stringify(e.errorDetail, undefined, 2), ); } else { console.error(e); @@ -399,10 +398,16 @@ async function runTaskLoop( try { await processOnePendingOperation(ws, p); } catch (e) { - if (e instanceof OperationFailedAndReportedError) { - logger.warn("operation processed resulted in reported error"); - logger.warn(`reported error was: ${j2s(e.operationError)}`); + if ( + e instanceof TalerError && + e.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED) + ) { + logger.warn("operation processed resulted in error"); + logger.warn(`error was: ${j2s(e.errorDetail)}`); } else { + // This is a bug, as we expect pending operations to always + // do their own error handling and only throw WALLET_PENDING_OPERATION_FAILED + // or return something. logger.error("Uncaught exception", e); ws.notify({ type: NotificationType.InternalError, @@ -722,7 +727,7 @@ export async function getClientFromWalletState( const res = await handleCoreApiRequest(ws, op, `${id++}`, payload); switch (res.type) { case "error": - throw new OperationFailedError(res.error); + throw TalerError.fromUncheckedDetail(res.error); case "response": return res.result; } @@ -1040,12 +1045,12 @@ async function dispatchRequestInternal( return []; } } - throw OperationFailedError.fromCode( + throw TalerError.fromDetail( TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN, - "unknown operation", { operation, }, + "unknown operation", ); } @@ -1067,34 +1072,13 @@ export async function handleCoreApiRequest( result, }; } catch (e: any) { - if ( - e instanceof OperationFailedError || - e instanceof OperationFailedAndReportedError - ) { - logger.error("Caught operation failed error"); - logger.trace((e as any).stack); - return { - type: "error", - operation, - id, - error: e.operationError, - }; - } else { - try { - logger.error("Caught unexpected exception:"); - logger.error(e.stack); - } catch (e) {} - return { - type: "error", - operation, - id, - error: makeErrorDetails( - TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION, - `unexpected exception: ${e}`, - {}, - ), - }; - } + const err = getErrorDetailFromException(e); + return { + type: "error", + operation, + id, + error: err, + }; } } |