commit 4c5f40781239ba295ade48854bc8e2f6228aa2ed
parent a3feb4c9f3eb133b856440365a9b1eee421e707b
Author: Florian Dold <florian@dold.me>
Date: Sun, 24 Aug 2025 15:47:01 +0200
wallet-core: report non-JSON /keys response from exchange with better error message
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
@@ -948,8 +948,22 @@ async function downloadExchangeKeysInfo(
// message about some other field, when it is just a version
// incompatibility.
- const keysJson = await resp.json();
+ let keysJson;
+ try {
+ keysJson = await resp.json();
+ } catch (e) {
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+ {
+ requestUrl: resp.requestUrl,
+ requestMethod: resp.requestMethod,
+ httpStatusCode: resp.status,
+ validationError: e instanceof Error ? e.message : String(e),
+ },
+ "Couldn't parse JSON format from response",
+ );
+ }
const protocolVersion = keysJson.version;
if (typeof protocolVersion !== "string") {
throw Error("bad exchange, does not even specify protocol version");