From 5b8924b8cfe14909b778ec096b3d893a9dde8533 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 24 Jul 2020 00:22:46 +0530 Subject: logging --- src/headless/helpers.ts | 2 +- src/headless/taler-wallet-cli.ts | 15 ++++++++++++--- src/operations/pay.ts | 4 +++- src/operations/reserves.ts | 12 ++++++++---- src/types/notifications.ts | 1 + 5 files changed, 25 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/headless/helpers.ts b/src/headless/helpers.ts index e451db55b..3b2f65313 100644 --- a/src/headless/helpers.ts +++ b/src/headless/helpers.ts @@ -79,7 +79,7 @@ export async function getDefaultNodeWallet( const dbContent = JSON.parse(dbContentStr); myBackend.importDump(dbContent); } catch (e) { - console.error("could not read wallet file"); + logger.warn("could not read wallet file"); } myBackend.afterCommitCallback = async () => { diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index ca168bf8a..2502ec7db 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -30,7 +30,10 @@ import { setupRefreshPlanchet, encodeCrock, } from "../crypto/talerCrypto"; -import { OperationFailedAndReportedError } from "../operations/errors"; +import { + OperationFailedAndReportedError, + OperationFailedError, +} from "../operations/errors"; import { Bank } from "./bank"; import { classifyTalerUri, TalerUriType } from "../util/taleruri"; import { Configuration } from "../util/talerconfig"; @@ -167,9 +170,15 @@ async function withWallet( const ret = await f(wallet); return ret; } catch (e) { - if (e instanceof OperationFailedAndReportedError) { + if ( + e instanceof OperationFailedAndReportedError || + e instanceof OperationFailedError + ) { console.error("Operation failed: " + e.message); - console.log("Hint: check pending operations for details."); + console.error( + "Error details:", + JSON.stringify(e.operationError, undefined, 2), + ); } else { console.error("caught unhandled exception (bug?):", e); } diff --git a/src/operations/pay.ts b/src/operations/pay.ts index 0027bf0f3..58911b4bf 100644 --- a/src/operations/pay.ts +++ b/src/operations/pay.ts @@ -783,6 +783,8 @@ export async function submitPay( coins: purchase.coinDepositPermissions, session_id: purchase.lastSessionId, }; + + logger.trace("making pay request", JSON.stringify(reqBody, undefined, 2)); const resp = await ws.http.postJson(payUrl, reqBody); @@ -791,7 +793,7 @@ export async function submitPay( codecForMerchantPayResponse(), ); - console.log("got success from pay URL", merchantResp); + logger.trace("got success from pay URL", merchantResp); const now = getTimestampNow(); diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts index 51499e448..6045b61d2 100644 --- a/src/operations/reserves.ts +++ b/src/operations/reserves.ts @@ -240,12 +240,18 @@ export async function createReserve( }, ); - ws.notify({ type: NotificationType.ReserveCreated }); + if (reserveRecord.reservePub === resp.reservePub) { + // Only emit notification when a new reserve was created. + ws.notify({ + type: NotificationType.ReserveCreated, + reservePub: reserveRecord.reservePub, + }); + } // Asynchronously process the reserve, but return // to the caller already. processReserve(ws, resp.reservePub, true).catch((e) => { - console.error("Processing reserve (after createReserve) failed:", e); + logger.error("Processing reserve (after createReserve) failed:", e); }); return resp; @@ -318,7 +324,6 @@ async function registerReserveWithBank( return; } const bankStatusUrl = bankInfo.statusUrl; - console.log("making selection"); if (reserve.timestampReserveInfoPosted) { throw Error("bank claims that reserve info selection is not done"); } @@ -788,7 +793,6 @@ export async function createTalerWithdrawReserve( // We do this here, as the reserve should be registered before we return, // so that we can redirect the user to the bank's status page. await processReserveBankStatus(ws, reserve.reservePub); - console.log("acceptWithdrawal: returning"); return { reservePub: reserve.reservePub, confirmTransferUrl: withdrawInfo.confirmTransferUrl, diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 5d6d2ee11..945b86eea 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -203,6 +203,7 @@ export interface ReserveOperationErrorNotification { export interface ReserveCreatedNotification { type: NotificationType.ReserveCreated; + reservePub: string; } export interface PendingOperationProcessedNotification { -- cgit v1.2.3