From a7b79a30e8198bfc88e01d6646f1b067b86e758b Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Wed, 23 Jun 2021 10:05:29 +0800 Subject: [PATCH] Print server error --- src/api.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api.js b/src/api.js index e0c666d..a218cc6 100644 --- a/src/api.js +++ b/src/api.js @@ -65,7 +65,14 @@ exports.closeSession = function () { async function query(url, options) { const resp = await fetch(url, options); - const json = await resp.json(); + const text = await resp.text(); + let json; + try { + json = JSON.parse(text); + } catch (e) { + throw new Error(`Server error: ${text}`); + } + if (resp.status !== 200) { throw Object.assign(new Error(json.message || json.error), { status: resp.status,