fix: correct error showing instead of client-side exception if release episodes data is failed to load

This commit is contained in:
Kentai Radiquum 2025-03-14 20:25:37 +05:00
parent 9f80ff3262
commit 046ef3a9a4
Signed by: Radiquum
GPG key ID: 858E8EE696525EED

View file

@ -162,32 +162,25 @@ export const ReleasePlayer = (props: { id: number }) => {
return; return;
}); });
if (data && Object.keys(data).length == 0) { if (!data || (data && Object.keys(data).length == 0)) {
_setError("Ошибка получение данных с сервера"); _setError("Ошибка получение данных с сервера");
return;
} }
if (type == "voiceover") { if (type == "voiceover") {
if (data.types.length > 0) {
setVoiceoverInfo(data.types); setVoiceoverInfo(data.types);
const preferredVoiceover = const preferredVoiceover =
data.types.find( data.types.find(
(voiceover: any) => voiceover.name === storedPreferredVoiceover (voiceover: any) => voiceover.name === storedPreferredVoiceover
) || data.types[0]; ) || data.types[0];
setSelectedVoiceover(preferredVoiceover); setSelectedVoiceover(preferredVoiceover);
} else {
_setError("Ошибка получения озвучек");
}
} else if (type == "sources") { } else if (type == "sources") {
if (data.sources.length > 0) {
setSourcesInfo(data.sources); setSourcesInfo(data.sources);
const preferredSource = const preferredSource =
data.sources.find( data.sources.find(
(source: any) => source.name === storedPreferredPlayer (source: any) => source.name === storedPreferredPlayer
) || data.sources[0]; ) || data.sources[0];
setSelectedSource(preferredSource); setSelectedSource(preferredSource);
} else {
_setError("Ошибка получения источников");
}
} else if (type == "episodes") { } else if (type == "episodes") {
if (data.episodes.length === 0) { if (data.episodes.length === 0) {
const remSources = sourcesInfo.filter( const remSources = sourcesInfo.filter(
@ -196,7 +189,7 @@ export const ReleasePlayer = (props: { id: number }) => {
setSourcesInfo(remSources); setSourcesInfo(remSources);
setSelectedSource(remSources[0]); setSelectedSource(remSources[0]);
return; return;
} else if (data.episodes.length > 0) { } else {
setEpisodeInfo(data.episodes); setEpisodeInfo(data.episodes);
setSelectedEpisode(data.episodes[0]); setSelectedEpisode(data.episodes[0]);
@ -220,8 +213,6 @@ export const ReleasePlayer = (props: { id: number }) => {
} }
setSelectedEpisode(data.episodes[lastWatchedEpisode]); setSelectedEpisode(data.episodes[lastWatchedEpisode]);
} }
} else {
_setError("Ошибка получения эпизодов");
} }
} else { } else {
_setError("Неизвестный тип запроса"); _setError("Неизвестный тип запроса");