diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-24 11:52:12 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-24 11:52:12 +0530 |
commit | b1fd7d09a605558bc61ed113331e0e065e0e2681 (patch) | |
tree | 1c25c1f9620413149e44c628655781172c85508b /packages/taler-wallet-core/src/operations | |
parent | 1548086f50a7e33f17c5a5218fa0fc3383a8a2d5 (diff) | |
download | wallet-core-b1fd7d09a605558bc61ed113331e0e065e0e2681.tar.xz |
test case for order claiming; more accurate EC
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay.ts | 23 |
1 files changed, 18 insertions, 5 deletions
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. |