added more error handeling to crunchyroll fetches

This commit is contained in:
stratuma 2024-05-22 01:17:04 +02:00
parent 119053c443
commit a22f70a017

View File

@ -31,7 +31,7 @@ export async function crunchyLogin(user: string, passw: string, geo: string) {
if (!cachedData) { if (!cachedData) {
if (geo === 'LOCAL') { if (geo === 'LOCAL') {
const data = await crunchyLoginFetch(user, passw); const data = await crunchyLoginFetch(user, passw)
if (!data) return if (!data) return
@ -64,14 +64,16 @@ async function crunchyLoginFetchProxy(user: string, passw: string, geo: string)
var endpoint = await settings.get('CREndpoint') var endpoint = await settings.get('CREndpoint')
const drmL3blob = await settings.get('l3blob') const drmL3blob = await settings.get('l3blob')
const drmL3key = await settings.get('l3key') const drmL3key = await settings.get('l3key')
var proxy: { var proxy:
name: string; | {
code: string; name: string
url: string; code: string
status: string | undefined; url: string
} | undefined; status: string | undefined
}
| undefined
proxy = proxies.find((p) => p.code === geo); proxy = proxies.find((p) => p.code === geo)
if (!proxy) { if (!proxy) {
messageBox('error', ['Cancel'], 2, 'Login Proxy not found', 'Login Proxy not found', `Login Proxy ${geo} not found`) messageBox('error', ['Cancel'], 2, 'Login Proxy not found', 'Login Proxy not found', `Login Proxy ${geo} not found`)
@ -354,8 +356,14 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
playlist = data playlist = data
} else { } else {
const error = await response.text() const error = await response.text()
messageBox('error', ['Cancel'], 2, 'Failed to get Crunchyroll Video Playlist', 'Failed to get Crunchyroll Video Playlist', error)
messageBox('error', ['Cancel'], 2, 'Failed to get MPD Playlist', 'Failed to get MPD Playlist', error) server.logger.log({
level: 'error',
message: 'Failed to get Crunchyroll Video Playlist',
error: error,
timestamp: new Date().toISOString(),
section: 'playlistCrunchyrollFetch'
})
throw new Error(error) throw new Error(error)
} }
} catch (e) { } catch (e) {
@ -438,10 +446,18 @@ export async function deleteVideoToken(content: string, token: string) {
if (response.ok) { if (response.ok) {
return 'ok' return 'ok'
} else { } else {
const error = await response.text()
messageBox('error', ['Cancel'], 2, 'Failed to delete Crunchyroll Video Token', 'Failed to delete Crunchyroll Video Token', error)
server.logger.log({
level: 'error',
message: 'Failed to delete Crunchyroll Video Token',
error: error,
timestamp: new Date().toISOString(),
section: 'tokenDeletionCrunchyrollFetch'
})
throw new Error(await response.text()) throw new Error(await response.text())
} }
} catch (e) { } catch (e) {
console.log('Delete token failed')
throw new Error(e as string) throw new Error(e as string)
} }
} }
@ -473,6 +489,15 @@ export async function crunchyGetPlaylistMPD(q: string, geo: string | undefined)
return parsed return parsed
} else { } else {
const error = await response.text()
messageBox('error', ['Cancel'], 2, 'Failed to get Crunchyroll MPD', 'Failed to get Crunchyroll MPD', error)
server.logger.log({
level: 'error',
message: 'Failed to get Crunchyroll MPD',
error: error,
timestamp: new Date().toISOString(),
section: 'mpdCrunchyrollFetch'
})
throw new Error(await response.text()) throw new Error(await response.text())
} }
} catch (e) { } catch (e) {