From 5d23eb36354d07508a015531f298b3e261bbafce Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 22 Mar 2022 21:16:38 +0100 Subject: wallet: improve error handling and error codes --- .../src/integrationtests/test-bank-api.ts | 5 ++-- .../src/integrationtests/test-denom-unoffered.ts | 32 +++++++++++----------- .../integrationtests/test-exchange-management.ts | 18 +++++++++--- .../src/integrationtests/test-pay-abort.ts | 2 +- .../src/integrationtests/test-payment-claim.ts | 30 ++++++++++++-------- .../src/integrationtests/test-payment-transient.ts | 8 ++---- .../src/integrationtests/test-wallet-dbless.ts | 6 ++-- .../integrationtests/test-withdrawal-abort-bank.ts | 4 +-- 8 files changed, 60 insertions(+), 45 deletions(-) (limited to 'packages/taler-wallet-cli/src/integrationtests') diff --git a/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts b/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts index 8a11b79c6..97dbf369c 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-bank-api.ts @@ -32,7 +32,6 @@ import { BankApi, BankAccessApi, CreditDebitIndicator, - OperationFailedError, } from "@gnu-taler/taler-wallet-core"; /** @@ -104,10 +103,10 @@ export async function runBankApiTest(t: GlobalTestState) { // Make sure that registering twice results in a 409 Conflict { - const e = await t.assertThrowsAsync(async () => { + const e = await t.assertThrowsTalerErrorAsync(async () => { await BankApi.registerAccount(bank, "user1", "pw1"); }); - t.assertTrue(e.details.httpStatusCode === 409); + t.assertTrue(e.errorDetail.httpStatusCode === 409); } let balResp = await BankAccessApi.getAccountBalance(bank, bankUser); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts b/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts index 28cca0758..ec1d9f64b 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-denom-unoffered.ts @@ -20,25 +20,21 @@ import { PreparePayResultType, TalerErrorCode, - TalerErrorDetails, - TransactionType, + TalerErrorDetail, } from "@gnu-taler/taler-util"; -import { - WalletApiOperation, -} from "@gnu-taler/taler-wallet-core"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { makeEventId } from "@gnu-taler/taler-wallet-core"; import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironment, withdrawViaBank } from "../harness/helpers.js"; +import { + createSimpleTestkudosEnvironment, + withdrawViaBank, +} from "../harness/helpers.js"; export async function runDenomUnofferedTest(t: GlobalTestState) { // Set up test environment - const { - wallet, - bank, - exchange, - merchant, - } = await createSimpleTestkudosEnvironment(t); + const { wallet, bank, exchange, merchant } = + await createSimpleTestkudosEnvironment(t); // Withdraw digital cash into the wallet. @@ -95,19 +91,23 @@ export async function runDenomUnofferedTest(t: GlobalTestState) { preparePayResult.status === PreparePayResultType.PaymentPossible, ); - const exc = await t.assertThrowsAsync(async () => { + const exc = await t.assertThrowsTalerErrorAsync(async () => { await wallet.client.call(WalletApiOperation.ConfirmPay, { proposalId: preparePayResult.proposalId, }); }); - const errorDetails: TalerErrorDetails = exc.operationError; + t.assertTrue( + exc.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED), + ); + // FIXME: We might want a more specific error code here! t.assertDeepEqual( - errorDetails.code, + exc.errorDetail.innerError.code, TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR, ); - const merchantErrorCode = (errorDetails.details as any).errorResponse.code; + const merchantErrorCode = (exc.errorDetail.innerError.errorResponse as any) + .code; t.assertDeepEqual( merchantErrorCode, TalerErrorCode.MERCHANT_POST_ORDERS_ID_PAY_DENOMINATION_KEY_NOT_FOUND, diff --git a/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts b/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts index f9c7c4b99..dc650830d 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts @@ -181,16 +181,22 @@ export async function runExchangeManagementTest(t: GlobalTestState) { }, }); - const err1 = await t.assertThrowsOperationErrorAsync(async () => { + const err1 = await t.assertThrowsTalerErrorAsync(async () => { await wallet.client.call(WalletApiOperation.AddExchange, { exchangeBaseUrl: faultyExchange.baseUrl, }); }); + // Updating the exchange from the base URL is technically a pending operation + // and it will be retried later. + t.assertTrue( + err1.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED), + ); + // Response is malformed, since it didn't even contain a version code // in a format the wallet can understand. t.assertTrue( - err1.operationError.code === + err1.errorDetail.innerError.code === TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, ); @@ -223,14 +229,18 @@ export async function runExchangeManagementTest(t: GlobalTestState) { }, }); - const err2 = await t.assertThrowsOperationErrorAsync(async () => { + const err2 = await t.assertThrowsTalerErrorAsync(async () => { await wallet.client.call(WalletApiOperation.AddExchange, { exchangeBaseUrl: faultyExchange.baseUrl, }); }); t.assertTrue( - err2.operationError.code === + err2.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED), + ); + + t.assertTrue( + err2.errorDetail.innerError.code === TalerErrorCode.WALLET_EXCHANGE_PROTOCOL_VERSION_INCOMPATIBLE, ); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts index 0fa9ec81d..09b546f46 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts @@ -123,7 +123,7 @@ export async function runPayAbortTest(t: GlobalTestState) { }, }); - await t.assertThrowsOperationErrorAsync(async () => { + await t.assertThrowsTalerErrorAsync(async () => { await wallet.client.call(WalletApiOperation.ConfirmPay, { proposalId: preparePayResult.proposalId, }); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts b/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts index ba3bd8e0a..e878854f8 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-claim.ts @@ -17,8 +17,15 @@ /** * Imports. */ -import { GlobalTestState, MerchantPrivateApi, WalletCli } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironment, withdrawViaBank } from "../harness/helpers.js"; +import { + GlobalTestState, + MerchantPrivateApi, + WalletCli, +} from "../harness/harness.js"; +import { + createSimpleTestkudosEnvironment, + withdrawViaBank, +} from "../harness/helpers.js"; import { PreparePayResultType } from "@gnu-taler/taler-util"; import { TalerErrorCode } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -29,12 +36,8 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; export async function runPaymentClaimTest(t: GlobalTestState) { // Set up test environment - const { - wallet, - bank, - exchange, - merchant, - } = await createSimpleTestkudosEnvironment(t); + const { wallet, bank, exchange, merchant } = + await createSimpleTestkudosEnvironment(t); const walletTwo = new WalletCli(t, "two"); @@ -73,7 +76,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) { preparePayResult.status === PreparePayResultType.PaymentPossible, ); - t.assertThrowsOperationErrorAsync(async () => { + t.assertThrowsTalerErrorAsync(async () => { await walletTwo.client.call(WalletApiOperation.PreparePayForUri, { talerPayUri, }); @@ -93,14 +96,19 @@ export async function runPaymentClaimTest(t: GlobalTestState) { walletTwo.deleteDatabase(); - const err = await t.assertThrowsOperationErrorAsync(async () => { + const err = await t.assertThrowsTalerErrorAsync(async () => { await walletTwo.client.call(WalletApiOperation.PreparePayForUri, { talerPayUri, }); }); t.assertTrue( - err.operationError.code === TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED, + err.hasErrorCode(TalerErrorCode.WALLET_PENDING_OPERATION_FAILED), + ); + + t.assertTrue( + err.errorDetail.innerError.code === + TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED, ); await t.shutdown(); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts b/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts index 75d44d495..7e178077e 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts @@ -32,7 +32,7 @@ import { ConfirmPayResultType, PreparePayResultType, TalerErrorCode, - TalerErrorDetails, + TalerErrorDetail, URL, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -135,11 +135,9 @@ export async function runPaymentTransientTest(t: GlobalTestState) { } faultInjected = true; console.log("injecting pay fault"); - const err: TalerErrorDetails = { + const err: TalerErrorDetail = { code: TalerErrorCode.GENERIC_DB_COMMIT_FAILED, - details: {}, - hint: "huh", - message: "something went wrong", + hint: "something went wrong", }; ctx.responseBody = Buffer.from(JSON.stringify(err)); ctx.statusCode = 500; diff --git a/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts b/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts index 93c22af70..146603f3a 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-wallet-dbless.ts @@ -26,9 +26,9 @@ import { findDenomOrThrow, generateReserveKeypair, NodeHttpLib, - OperationFailedError, refreshCoin, SynchronousCryptoWorkerFactory, + TalerError, topupReserveWithDemobank, withdrawCoin, } from "@gnu-taler/taler-wallet-core"; @@ -95,9 +95,9 @@ export async function runWalletDblessTest(t: GlobalTestState) { newDenoms: refreshDenoms, }); } catch (e) { - if (e instanceof OperationFailedError) { + if (e instanceof TalerError) { console.log(e); - console.log(j2s(e.operationError)); + console.log(j2s(e.errorDetail)); } else { console.log(e); } diff --git a/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts b/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts index 19668d760..0125b3b41 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-withdrawal-abort-bank.ts @@ -63,7 +63,7 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) { // // WHY ?! // - const e = await t.assertThrowsOperationErrorAsync(async () => { + const e = await t.assertThrowsTalerErrorAsync(async () => { await wallet.client.call( WalletApiOperation.AcceptBankIntegratedWithdrawal, { @@ -73,7 +73,7 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) { ); }); t.assertDeepEqual( - e.operationError.code, + e.errorDetail.code, TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK, ); -- cgit v1.2.3