aboutsummaryrefslogtreecommitdiff
path: root/src/wallet-impl/reserves.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-09 13:29:11 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-09 13:29:11 +0100
commit1fea75bca3951d39c0a45faf3e903fcec77f9c4f (patch)
tree8d582e26a7e583871e0c9c223976e67b93ef2059 /src/wallet-impl/reserves.ts
parent396bb61db70f654599256e512bfec4c008ee8269 (diff)
downloadwallet-core-1fea75bca3951d39c0a45faf3e903fcec77f9c4f.tar.xz
throttling / allow non-json requests
Diffstat (limited to 'src/wallet-impl/reserves.ts')
-rw-r--r--src/wallet-impl/reserves.ts29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/wallet-impl/reserves.ts b/src/wallet-impl/reserves.ts
index d6568bd30..504cf10f0 100644
--- a/src/wallet-impl/reserves.ts
+++ b/src/wallet-impl/reserves.ts
@@ -282,7 +282,10 @@ async function processReserveBankStatusImpl(
let status: WithdrawOperationStatusResponse;
try {
const statusResp = await ws.http.get(bankStatusUrl);
- status = WithdrawOperationStatusResponse.checked(statusResp.responseJson);
+ if (statusResp.status !== 200) {
+ throw Error(`unexpected status ${statusResp.status} for bank status query`);
+ }
+ status = WithdrawOperationStatusResponse.checked(await statusResp.json());
} catch (e) {
throw e;
}
@@ -378,22 +381,24 @@ async function updateReserve(
let resp;
try {
resp = await ws.http.get(reqUrl.href);
- } catch (e) {
- if (e.response?.status === 404) {
+ if (resp.status === 404) {
const m = "The exchange does not know about this reserve (yet).";
await incrementReserveRetry(ws, reservePub, undefined);
return;
- } else {
- const m = e.message;
- await incrementReserveRetry(ws, reservePub, {
- type: "network",
- details: {},
- message: m,
- });
- throw new OperationFailedAndReportedError(m);
}
+ if (resp.status !== 200) {
+ throw Error(`unexpected status code ${resp.status} for reserve/status`)
+ }
+ } catch (e) {
+ const m = e.message;
+ await incrementReserveRetry(ws, reservePub, {
+ type: "network",
+ details: {},
+ message: m,
+ });
+ throw new OperationFailedAndReportedError(m);
}
- const reserveInfo = ReserveStatus.checked(resp.responseJson);
+ const reserveInfo = ReserveStatus.checked(await resp.json());
const balance = Amounts.parseOrThrow(reserveInfo.balance);
await oneShotMutate(ws.db, Stores.reserves, reserve.reservePub, r => {
if (r.reserveStatus !== ReserveRecordStatus.QUERYING_STATUS) {