diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-07-20 17:46:49 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-07-20 17:46:49 +0530 |
commit | dd2efc3d78f2dfda44f8182f9638723dcb839781 (patch) | |
tree | 9cfbd31607f044fb80da80d8f740ae5eaa21a2f4 /src/operations/recoup.ts | |
parent | 5a8931d90320ebc8454969ea133c48b6998ad60a (diff) | |
download | wallet-core-dd2efc3d78f2dfda44f8182f9638723dcb839781.tar.xz |
nicer HTTP helper in preparation for better error handling
Diffstat (limited to 'src/operations/recoup.ts')
-rw-r--r-- | src/operations/recoup.ts | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/operations/recoup.ts b/src/operations/recoup.ts index e1c2325d7..d1b3c3bda 100644 --- a/src/operations/recoup.ts +++ b/src/operations/recoup.ts @@ -48,7 +48,8 @@ import { RefreshReason, OperationError } from "../types/walletTypes"; import { TransactionHandle } from "../util/query"; import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; import { getTimestampNow } from "../util/time"; -import { guardOperationException, scrutinizeTalerJsonResponse } from "./errors"; +import { guardOperationException } from "./errors"; +import { httpPostTalerJson } from "../util/http"; async function incrementRecoupRetry( ws: InternalWalletState, @@ -146,11 +147,12 @@ async function recoupWithdrawCoin( const recoupRequest = await ws.cryptoApi.createRecoupRequest(coin); const reqUrl = new URL(`/coins/${coin.coinPub}/recoup`, coin.exchangeBaseUrl); - const resp = await ws.http.postJson(reqUrl.href, recoupRequest); - const recoupConfirmation = await scrutinizeTalerJsonResponse( - resp, - codecForRecoupConfirmation(), - ); + const recoupConfirmation = await httpPostTalerJson({ + url: reqUrl.href, + body: recoupRequest, + codec: codecForRecoupConfirmation(), + http: ws.http, + }); if (recoupConfirmation.reserve_pub !== reservePub) { throw Error(`Coin's reserve doesn't match reserve on recoup`); @@ -220,11 +222,13 @@ async function recoupRefreshCoin( const recoupRequest = await ws.cryptoApi.createRecoupRequest(coin); const reqUrl = new URL(`/coins/${coin.coinPub}/recoup`, coin.exchangeBaseUrl); console.log("making recoup request"); - const resp = await ws.http.postJson(reqUrl.href, recoupRequest); - const recoupConfirmation = await scrutinizeTalerJsonResponse( - resp, - codecForRecoupConfirmation(), - ); + + const recoupConfirmation = await httpPostTalerJson({ + url: reqUrl.href, + body: recoupRequest, + codec: codecForRecoupConfirmation(), + http: ws.http, + }); if (recoupConfirmation.old_coin_pub != cs.oldCoinPub) { throw Error(`Coin's oldCoinPub doesn't match reserve on recoup`); |