diff --git a/common/modules/myanimelist.js b/common/modules/myanimelist.js index 31fccae..b04914a 100644 --- a/common/modules/myanimelist.js +++ b/common/modules/myanimelist.js @@ -119,16 +119,16 @@ class MALClient { } catch (e) { if (!res || res.status !== 404) throw e } - if (!res.ok && (res.status === 429 || res.status === 500)) { + if (!res?.ok && (res?.status === 429 || res?.status === 500)) { throw res } let json = null try { json = await res.json() } catch (error) { - if (res.ok) printError(error) + if (res?.ok) printError(error) } - if (!res.ok && res.status !== 404) { + if (!res?.ok && res?.status !== 404) { if (json) { for (const error of json?.errors || [json?.error] || []) { let code = error @@ -154,7 +154,7 @@ class MALClient { code = 422 break default: - code = res.status + code = res?.status } printError(code) } diff --git a/common/modules/settings.js b/common/modules/settings.js index 2162d14..a2df937 100644 --- a/common/modules/settings.js +++ b/common/modules/settings.js @@ -148,8 +148,8 @@ export async function refreshMalToken (token) { }) }) } - if (!refresh || !(refresh.length > 0) || !response.ok) { - toast.error('Failed to re-authenticate with MyAnimeList. You will need to log in again.', { description: JSON.stringify(response.status) }) + if (!refresh || !(refresh.length > 0) || !response?.ok) { + toast.error('Failed to re-authenticate with MyAnimeList. You will need to log in again.', { description: JSON.stringify(response?.status || response) }) debug(`Failed to refresh MyAnimeList User Token ${ !refresh || !(refresh.length > 0) ? 'as the refresh token could not be fetched!' : ': ' + JSON.stringify(response)}`) if (malToken?.token === token) { swapProfiles(null)