From 88e65b0498b7cdb785cb67dac9539092b8ad0a7f Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Sun, 23 Aug 2020 21:26:54 +0300 Subject: [PATCH] Patch generated js to work with non-json onError See https://github.com/haskell-servant/servant-js/issues/43 --- README.md | 5 +++++ js/queries.js | 21 +++------------------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 778d7a1..c72d201 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,8 @@ You'll need `libpcre3-dev` + `libmariadbclient-dev` (this is what they're called This build is in place so that you can easily run a "dev" server afterwards, refer to [Running](#Running). Building it on your machine might cause a `libc` mismatch between what is in the "deploy" image. + +## Modifications to js query functions + +Since servant doesn't return json-encoded values for errors (it's plaintext) the js functions need to be modified not to attempt +to parse the error body as json. diff --git a/js/queries.js b/js/queries.js index 0d3890a..97ef0de 100644 --- a/js/queries.js +++ b/js/queries.js @@ -15,12 +15,7 @@ const getApiTask = function (backendUrl, onSuccess, onError) { } if (res) onSuccess(res) } else { - try { - res = JSON.parse(xhr.responseText) - } catch (e) { - onError(e) - } - if (res) onError(res) + if (xhr.responseText) onError(xhr.responseText) } } } @@ -45,12 +40,7 @@ const postApiTask = function (backendUrl, body, onSuccess, onError) { } if (res) onSuccess(res) } else { - try { - res = JSON.parse(xhr.responseText) - } catch (e) { - onError(e) - } - if (res) onError(res) + if (xhr.responseText) onError(xhr.responseText) } } } @@ -75,12 +65,7 @@ const postApiSubmit = function (backendUrl, body, onSuccess, onError) { } if (res) onSuccess(res) } else { - try { - res = JSON.parse(xhr.responseText) - } catch (e) { - onError(e) - } - if (res) onError(res) + if (xhr.responseText) onError(xhr.responseText) } } }