fix: mal refresh

This commit is contained in:
RockinChaos 2024-09-11 02:20:47 -07:00
parent 8f144f4352
commit 8f5ee3439f
2 changed files with 6 additions and 6 deletions

View file

@ -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)
}

View file

@ -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)