From ac7fa99c4516e23040c60ad0b0fdd0437bae9288 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sun, 24 Dec 2023 16:37:00 +0100 Subject: [PATCH] Fix noOutput parsing + better error modal --- src/backend/helpers/providerApi.ts | 9 +++++++-- src/pages/parts/player/ScrapeErrorPart.tsx | 12 +++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backend/helpers/providerApi.ts b/src/backend/helpers/providerApi.ts index 0b6e07a3..528e392c 100644 --- a/src/backend/helpers/providerApi.ts +++ b/src/backend/helpers/providerApi.ts @@ -94,6 +94,11 @@ export async function getApiToken(): Promise { return apiToken; } +function parseEventInput(inp: string): any { + if (inp.length === 0) return {}; + return JSON.parse(inp); +} + export async function connectServerSideEvents( url: string, endEvents: string[], @@ -115,12 +120,12 @@ export async function connectServerSideEvents( endEvents.forEach((evt) => { eventSource.addEventListener(evt, (e) => { eventSource.close(); - promResolve(JSON.parse(e.data)); + promResolve(parseEventInput(e.data)); }); }); eventSource.addEventListener("token", (e) => { - setApiToken(JSON.parse(e.data)); + setApiToken(parseEventInput(e.data)); }); eventSource.addEventListener("error", (err: MessageEvent) => { diff --git a/src/pages/parts/player/ScrapeErrorPart.tsx b/src/pages/parts/player/ScrapeErrorPart.tsx index 52901786..6b52c796 100644 --- a/src/pages/parts/player/ScrapeErrorPart.tsx +++ b/src/pages/parts/player/ScrapeErrorPart.tsx @@ -1,5 +1,6 @@ import { useMemo } from "react"; import { useTranslation } from "react-i18next"; +import { useLocation } from "react-router-dom"; import { Button } from "@/components/buttons/Button"; import { Icons } from "@/components/Icon"; @@ -9,6 +10,7 @@ import { Paragraph } from "@/components/text/Paragraph"; import { Title } from "@/components/text/Title"; import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape"; import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout"; +import { getProviderApiUrls } from "@/utils/proxyUrls"; import { ErrorCardInModal } from "../errors/ErrorCard"; @@ -22,21 +24,21 @@ export interface ScrapeErrorPartProps { export function ScrapeErrorPart(props: ScrapeErrorPartProps) { const { t } = useTranslation(); const modal = useModal("error"); + const location = useLocation(); const error = useMemo(() => { const data = props.data; - const amountError = Object.values(data.sources).filter( - (v) => v.status === "failure", - ); - if (amountError.length === 0) return null; let str = ""; + const apiUrls = getProviderApiUrls(); + str += `URL - ${location.pathname}\n`; + str += `API - ${apiUrls.length > 0}\n\n`; Object.values(data.sources).forEach((v) => { str += `${v.id}: ${v.status}\n`; if (v.reason) str += `${v.reason}\n`; if (v.error) str += `${v.error.toString()}\n`; }); return str; - }, [props]); + }, [props, location]); return (