From d5eb8d8644fae3abf7616180a941f6793546a937 Mon Sep 17 00:00:00 2001 From: Spicer Matthews Date: Thu, 26 Sep 2024 16:42:58 -0700 Subject: [PATCH] Better error handling with logging tabs --- src/pages/index.js | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/pages/index.js b/src/pages/index.js index d740d89b..ec7702ee 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -437,24 +437,38 @@ const Index = ({ data: fallbackData, userAgent }) => { const enableBackgroundImages = showBackgroundImages() const logTabWithV5 = async () => { - const userToken = localStorageMgr.getItem('access_token') + try { + const userToken = localStorageMgr.getItem('access_token') - // This should not happen - if (!userToken) { - return - } + // This should not happen + if (!userToken) { + return + } - const headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: `Bearer ${userToken}`, - } + const headers = { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: `Bearer ${userToken}`, + } + + const response = await fetch( + `${process.env.NEXT_PUBLIC_API_ENDPOINT}/api/v1/tab/log`, + { + method: 'POST', + headers, + body: JSON.stringify({}), + } + ) - fetch(`${process.env.NEXT_PUBLIC_API_ENDPOINT}/api/v1/tab/log`, { - method: 'POST', - headers, - body: JSON.stringify({}), - }) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + } catch (error) { + console.error( + 'logTabWithV5: There was a problem with the fetch operation:', + error + ) + } } useEffect(() => {