diff options
author | 2021-09-02 22:28:11 +0200 | |
---|---|---|
committer | 2021-09-02 23:54:56 +0200 | |
commit | f08f6ca0a9d337efff280d4d1669a41b5d9c31c2 (patch) | |
tree | 7dee778ba742deb5f499f2aa08a1ba040606d633 /helpers/fetchJson.js | |
parent | 9f74c550927671f4ded301d0cf3e9d592716375c (diff) | |
download | my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.gz my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.bz2 my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.zip |
finish translations, force maximize
Diffstat (limited to 'helpers/fetchJson.js')
-rw-r--r-- | helpers/fetchJson.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/helpers/fetchJson.js b/helpers/fetchJson.js new file mode 100644 index 0000000..5db80b5 --- /dev/null +++ b/helpers/fetchJson.js @@ -0,0 +1,23 @@ +export default async function fetcher(...args) { + try { + const response = await fetch(...args) + + // if the server replies, there's always some data in json + // if there's a network error, it will throw at the previous line + const data = await response.json() + + if (response.ok) { + return data + } + + const error = new Error(response.statusText) + error.response = response + error.data = data + throw error + } catch (error) { + if (!error.data) { + error.data = {message: error.message} + } + throw error + } +} |