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,24 +18,26 @@ export async function fetchUpdate() {
}) })
if (!Number.isInteger(response.version)) { 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 // TODO: parse answer
this.version = parseInt(response.version) this.version = parseInt(response.version)
} catch (e) { } catch (e) {
if (!e.response) { if (e.response) {
// request aborted or other causes // callApi() threw an exception
return const { status, statusText } = e.response
} if (status == 200) {
delay = 1000
const { status, statusText } = e.response } else {
if (status == 200) { console.warn(`HTTP ${status} ${statusText}`)
delay = 1000 delay = 5000
this.version = -1
}
} else { } else {
console.warn(`HTTP ${status} ${statusText}`) // request aborted or other causes
delay = 5000 console.warn(e.message)
this.version = -1 return
} }
} }

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}