aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils.js
diff options
context:
space:
mode:
authorsecondl1ght <[email protected]>2022-08-02 13:24:51 -0600
committersecondl1ght <[email protected]>2022-08-02 13:24:51 -0600
commit1b7bdfb4797c9c6d5aeab0149c5fed352df9080a (patch)
treee770849d2aa0efde4fe01c3efdc4d31b7f0ba1fe /src/lib/utils.js
parentd99a3524fd2649f1a9ce3623333de56a99e06971 (diff)
parent05f5001fc7d325e31d9c777be11343604c72fbfd (diff)
downloadcoinos-ui-1b7bdfb4797c9c6d5aeab0149c5fed352df9080a.tar.gz
coinos-ui-1b7bdfb4797c9c6d5aeab0149c5fed352df9080a.zip
Merge branch 'master' of github.com:coinos/coinos-ui-v2
Diffstat (limited to 'src/lib/utils.js')
-rw-r--r--src/lib/utils.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/lib/utils.js b/src/lib/utils.js
index 6b728152..a812c136 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -14,7 +14,7 @@ export const get = (url, headers = { accept: 'application/json' }) =>
try {
return JSON.parse(body);
} catch (e) {
- throw Error(body);
+ throw new Error(body);
}
});
@@ -23,7 +23,20 @@ export const post = (url, body) =>
method: 'POST',
body: JSON.stringify(body),
headers: { accept: 'application/json', 'content-type': 'application/json' }
- }).then((r) => r.json());
+ })
+ .then((r) => r.text())
+ .then((body) => {
+ try {
+ body = JSON.parse(body);
+ } catch (e) {
+ throw new Error(body);
+ }
+
+ if (body instanceof Error) throw body;
+ if (body.name === 'Error') throw new Error(body.message);
+
+ return body;
+ });
export const copy = (text) => {
navigator.clipboard.writeText(text);