aboutsummaryrefslogtreecommitdiff
path: root/src/wallet-impl/exchanges.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/exchanges.ts
parent396bb61db70f654599256e512bfec4c008ee8269 (diff)
throttling / allow non-json requests
Diffstat (limited to 'src/wallet-impl/exchanges.ts')
-rw-r--r--src/wallet-impl/exchanges.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/wallet-impl/exchanges.ts b/src/wallet-impl/exchanges.ts
index 42d626a71..9810b9b91 100644
--- a/src/wallet-impl/exchanges.ts
+++ b/src/wallet-impl/exchanges.ts
@@ -112,7 +112,11 @@ async function updateExchangeWithKeys(
let keysResp;
try {
- keysResp = await ws.http.get(keysUrl.href);
+ const r = await ws.http.get(keysUrl.href);
+ if (r.status !== 200) {
+ throw Error(`unexpected status for keys: ${r.status}`);
+ }
+ keysResp = await r.json();
} catch (e) {
const m = `Fetching keys failed: ${e.message}`;
await setExchangeError(ws, baseUrl, {
@@ -126,7 +130,7 @@ async function updateExchangeWithKeys(
}
let exchangeKeysJson: KeysJson;
try {
- exchangeKeysJson = KeysJson.checked(keysResp.responseJson);
+ exchangeKeysJson = KeysJson.checked(keysResp);
} catch (e) {
const m = `Parsing /keys response failed: ${e.message}`;
await setExchangeError(ws, baseUrl, {
@@ -242,8 +246,10 @@ async function updateExchangeWithWireInfo(
reqUrl.searchParams.set("cacheBreaker", WALLET_CACHE_BREAKER_CLIENT_VERSION);
const resp = await ws.http.get(reqUrl.href);
-
- const wiJson = resp.responseJson;
+ if (resp.status !== 200) {
+ throw Error(`/wire response has unexpected status code (${resp.status})`);
+ }
+ const wiJson = await resp.json();
if (!wiJson) {
throw Error("/wire response malformed");
}