From 97a87b5b95abbad64433c676974eed949e2daf08 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 24 Sep 2022 01:40:22 +0200 Subject: [PATCH] Suppress "Failed to fetch" exception for version check (#2050) --- src/global/actions/ui/misc.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/global/actions/ui/misc.ts b/src/global/actions/ui/misc.ts index e663f381b..669064313 100644 --- a/src/global/actions/ui/misc.ts +++ b/src/global/actions/ui/misc.ts @@ -2,7 +2,7 @@ import { addActionHandler, getGlobal, setGlobal } from '../../index'; import type { ApiError } from '../../../api/types'; -import { APP_VERSION, GLOBAL_STATE_CACHE_CUSTOM_EMOJI_LIMIT } from '../../../config'; +import { APP_VERSION, DEBUG, GLOBAL_STATE_CACHE_CUSTOM_EMOJI_LIMIT } from '../../../config'; import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../../util/environment'; import getReadableErrorText from '../../../util/getReadableErrorText'; import { selectChatMessage, selectCurrentMessageList, selectIsTrustedBot } from '../../selectors'; @@ -409,9 +409,8 @@ addActionHandler('checkAppVersion', () => { const APP_VERSION_REGEX = /^\d+\.\d+(\.\d+)?$/; fetch(`${APP_VERSION_URL}?${Date.now()}`) - .then((response) => { - return response.text(); - }).then((version) => { + .then((response) => response.text()) + .then((version) => { version = version.trim(); if (APP_VERSION_REGEX.test(version) && version !== APP_VERSION) { @@ -420,5 +419,11 @@ addActionHandler('checkAppVersion', () => { isUpdateAvailable: true, }); } + }) + .catch((err) => { + if (DEBUG) { + // eslint-disable-next-line no-console + console.error('[checkAppVersion failed] ', err); + } }); });