Commit 483c2373 authored by David Trattnig's avatar David Trattnig
Browse files

API: Add bad response handling

parent a5d82ae5
......@@ -6,7 +6,12 @@
export async function fetchApi(url, callback) {
console.log('API Query: ' + url)
await fetch(url)
.then((r) => r.json())
.then((response) => {
if (response.status >= 400 && response.status < 600) {
throw new Error(`${response.status} | Bad response from server`)
}
return response.json()
})
.then((data) => callback(data))
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment