From 56d9c3957175aa15e9a1cb04469a843ab044652e Mon Sep 17 00:00:00 2001 From: Emily Davis Date: Mon, 11 Nov 2024 16:53:21 -0700 Subject: [PATCH] Add error handling --- .../renderer/components/Changelog/index.jsx | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/workbench/src/renderer/components/Changelog/index.jsx b/workbench/src/renderer/components/Changelog/index.jsx index 3ae2114de..933db6675 100644 --- a/workbench/src/renderer/components/Changelog/index.jsx +++ b/workbench/src/renderer/components/Changelog/index.jsx @@ -9,6 +9,7 @@ import pkg from '../../../../package.json'; import { ipcMainChannels } from '../../../main/ipcMainChannels'; const { ipcRenderer } = window.Workbench.electron; +const { logger } = window.Workbench; export default function Changelog(props) { const { t } = useTranslation(); @@ -17,30 +18,36 @@ export default function Changelog(props) { // Load HTML from external file (which is generated by Python build process). useEffect(() => { async function loadHtml() { - const baseUrl = await ipcRenderer.invoke(ipcMainChannels.BASE_URL) - fetch(`${baseUrl}/changelog.html`) - .then(response => response.text()) - .then(htmlString => { - // Find the section whose heading explicitly matches the current version. - const versionStr = pkg.version; - const escapedVersionStr = versionStr.split('.').join('\\.'); - const sectionRegex = new RegExp( - `[\\s]*?

${escapedVersionStr}\\b[\\s\\S]*?

[\\s\\S]*?` + const baseUrl = await ipcRenderer.invoke(ipcMainChannels.BASE_URL); + const response = await fetch(`${baseUrl}/changelog.html`); + if (!response.ok) { + logger.debug(`Error fetching changelog HTML: ${response.status} ${response.statusText}`); + return; + } + try { + const htmlString = await response.text(); + // Find the section whose heading explicitly matches the current version. + const versionStr = pkg.version; + const escapedVersionStr = versionStr.split('.').join('\\.'); + const sectionRegex = new RegExp( + `[\\s]*?

${escapedVersionStr}\\b[\\s\\S]*?

[\\s\\S]*?` + ); + const sectionMatches = htmlString.match(sectionRegex); + if (sectionMatches && sectionMatches.length) { + let latestVersionSection = sectionMatches[0]; + const linkRegex = /