From 046ef3a9a4f00bf27d25360d6102f0d69e86032b Mon Sep 17 00:00:00 2001 From: Radiquum Date: Fri, 14 Mar 2025 20:25:37 +0500 Subject: [PATCH] fix: correct error showing instead of client-side exception if release episodes data is failed to load --- .../ReleasePlayer/ReleasePlayer.tsx | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/app/components/ReleasePlayer/ReleasePlayer.tsx b/app/components/ReleasePlayer/ReleasePlayer.tsx index e077b9b..f6c13d5 100644 --- a/app/components/ReleasePlayer/ReleasePlayer.tsx +++ b/app/components/ReleasePlayer/ReleasePlayer.tsx @@ -162,32 +162,25 @@ export const ReleasePlayer = (props: { id: number }) => { return; }); - if (data && Object.keys(data).length == 0) { + if (!data || (data && Object.keys(data).length == 0)) { _setError("Ошибка получение данных с сервера"); + return; } if (type == "voiceover") { - if (data.types.length > 0) { - setVoiceoverInfo(data.types); - const preferredVoiceover = - data.types.find( - (voiceover: any) => voiceover.name === storedPreferredVoiceover - ) || data.types[0]; - setSelectedVoiceover(preferredVoiceover); - } else { - _setError("Ошибка получения озвучек"); - } + setVoiceoverInfo(data.types); + const preferredVoiceover = + data.types.find( + (voiceover: any) => voiceover.name === storedPreferredVoiceover + ) || data.types[0]; + setSelectedVoiceover(preferredVoiceover); } else if (type == "sources") { - if (data.sources.length > 0) { - setSourcesInfo(data.sources); - const preferredSource = - data.sources.find( - (source: any) => source.name === storedPreferredPlayer - ) || data.sources[0]; - setSelectedSource(preferredSource); - } else { - _setError("Ошибка получения источников"); - } + setSourcesInfo(data.sources); + const preferredSource = + data.sources.find( + (source: any) => source.name === storedPreferredPlayer + ) || data.sources[0]; + setSelectedSource(preferredSource); } else if (type == "episodes") { if (data.episodes.length === 0) { const remSources = sourcesInfo.filter( @@ -196,7 +189,7 @@ export const ReleasePlayer = (props: { id: number }) => { setSourcesInfo(remSources); setSelectedSource(remSources[0]); return; - } else if (data.episodes.length > 0) { + } else { setEpisodeInfo(data.episodes); setSelectedEpisode(data.episodes[0]); @@ -220,8 +213,6 @@ export const ReleasePlayer = (props: { id: number }) => { } setSelectedEpisode(data.episodes[lastWatchedEpisode]); } - } else { - _setError("Ошибка получения эпизодов"); } } else { _setError("Неизвестный тип запроса");