diff options
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/TalerErrorCode.ts | 7 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/headless/NodeHttpLib.ts | 5 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay.ts | 23 |
3 files changed, 30 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/TalerErrorCode.ts b/packages/taler-wallet-core/src/TalerErrorCode.ts index ff8511046..7285a0fbe 100644 --- a/packages/taler-wallet-core/src/TalerErrorCode.ts +++ b/packages/taler-wallet-core/src/TalerErrorCode.ts @@ -3210,6 +3210,13 @@ export enum TalerErrorCode { WALLET_HTTP_REQUEST_TIMEOUT = 7013, /** + * The order has already been claimed by another wallet. + * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * (A value of 0 indicates that the error is generated client-side). + */ + WALLET_ORDER_ALREADY_CLAIMED = 7014, + + /** * End of error code range. * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). * (A value of 0 indicates that the error is generated client-side). diff --git a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts index 85f37cfa3..62ab9caf6 100644 --- a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts +++ b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts @@ -30,6 +30,9 @@ import Axios from "axios"; import { OperationFailedError, makeErrorDetails } from "../operations/errors"; import { TalerErrorCode } from "../TalerErrorCode"; import { URL } from "../util/url"; +import { Logger } from "../util/logging"; + +const logger = new Logger("NodeHttpLib.ts"); /** * Implementation of the HTTP request library interface for node. @@ -96,6 +99,7 @@ export class NodeHttpLib implements HttpRequestLibrary { try { responseJson = JSON.parse(respText); } catch (e) { + logger.trace(`invalid json: '${respText}'`); throw new OperationFailedError( makeErrorDetails( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, @@ -109,6 +113,7 @@ export class NodeHttpLib implements HttpRequestLibrary { ); } if (responseJson === null || typeof responseJson !== "object") { + logger.trace(`invalid json (not an object): '${respText}'`); throw new OperationFailedError( makeErrorDetails( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts index f20632344..0d1d4f993 100644 --- a/packages/taler-wallet-core/src/operations/pay.ts +++ b/packages/taler-wallet-core/src/operations/pay.ts @@ -71,6 +71,7 @@ import { readSuccessResponseJsonOrThrow, throwUnexpectedRequestError, getHttpResponseErrorDetails, + readSuccessResponseJsonOrErrorCode, } from "../util/http"; import { TalerErrorCode } from "../TalerErrorCode"; import { URL } from "../util/url"; @@ -638,13 +639,25 @@ async function processDownloadProposalImpl( requestBody.token = proposal.claimToken; } - const resp = await ws.http.postJson(orderClaimUrl, requestBody, { + const httpResponse = await ws.http.postJson(orderClaimUrl, requestBody, { timeout: getProposalRequestTimeout(proposal), }); - const proposalResp = await readSuccessResponseJsonOrThrow( - resp, - codecForProposal(), - ); + const r = await readSuccessResponseJsonOrErrorCode(httpResponse, codecForProposal()); + if (r.isError) { + switch (r.talerErrorResponse.code) { + case TalerErrorCode.ORDERS_ALREADY_CLAIMED: + throw OperationFailedError.fromCode( + TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED, + "order already claimed (likely by other wallet)", + { + orderId: proposal.orderId, + claimUrl: orderClaimUrl, + }); + default: + throwUnexpectedRequestError(httpResponse, r.talerErrorResponse); + } + } + const proposalResp = r.response; // The proposalResp contains the contract terms as raw JSON, // as the coded to parse them doesn't necessarily round-trip. |