From 2465e87a86a272c4314c3bc04dff1bab74b9edcd Mon Sep 17 00:00:00 2001 From: Settel Date: Wed, 3 Aug 2022 23:00:34 +0200 Subject: [PATCH] refactor: improve engine error handling --- client/src/composables/engine/fetchUpdate.ts | 26 ++++++++++--------- .../d06fb83a-51eb-477e-b57c-6138a38eecb5.json | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/src/composables/engine/fetchUpdate.ts b/client/src/composables/engine/fetchUpdate.ts index b003edf..24e3441 100644 --- a/client/src/composables/engine/fetchUpdate.ts +++ b/client/src/composables/engine/fetchUpdate.ts @@ -18,24 +18,26 @@ 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 - } - - const { status, statusText } = e.response - if (status == 200) { - delay = 1000 + if (e.response) { + // callApi() threw an exception + const { status, statusText } = e.response + if (status == 200) { + delay = 1000 + } else { + console.warn(`HTTP ${status} ${statusText}`) + delay = 5000 + this.version = -1 + } } else { - console.warn(`HTTP ${status} ${statusText}`) - delay = 5000 - this.version = -1 + // request aborted or other causes + console.warn(e.message) + return } } diff --git a/server/data/users/d06fb83a-51eb-477e-b57c-6138a38eecb5.json b/server/data/users/d06fb83a-51eb-477e-b57c-6138a38eecb5.json index 8f4b5e5..942e5ff 100644 --- a/server/data/users/d06fb83a-51eb-477e-b57c-6138a38eecb5.json +++ b/server/data/users/d06fb83a-51eb-477e-b57c-6138a38eecb5.json @@ -1 +1 @@ -{"authcode":"123456","name":"Harry","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831122,"lastLoggedIn":1659475977} \ No newline at end of file +{"authcode":"123456","name":"Harry","role":"player","game":"663576f0-1378-496b-a970-578bdcb222af","created":1650831122,"lastLoggedIn":1659540828} \ No newline at end of file