refactor: improve engine error handling

This commit is contained in:
Settel 2022-08-03 23:00:34 +02:00
parent af19fd33fc
commit 2465e87a86
2 changed files with 15 additions and 13 deletions

View File

@ -18,17 +18,14 @@ export async function fetchUpdate() {
})
if (!Number.isInteger(response.version)) {
throw Error('unexpected response for sync, property version not found.')
throw Error('unexpected response from /api/sync')
}
// TODO: parse answer
this.version = parseInt(response.version)
} catch (e) {
if (!e.response) {
// request aborted or other causes
return
}
if (e.response) {
// callApi() threw an exception
const { status, statusText } = e.response
if (status == 200) {
delay = 1000
@ -37,6 +34,11 @@ export async function fetchUpdate() {
delay = 5000
this.version = -1
}
} else {
// request aborted or other causes
console.warn(e.message)
return
}
}
window.setTimeout(() => {

View File

@ -1 +1 @@
{"authcode":"123456","name":"Harry","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831122,"lastLoggedIn":1659475977}
{"authcode":"123456","name":"Harry","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831122,"lastLoggedIn":1659540828}