diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cbea2f22..2065790f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- Fixed admin toast leaking a raw `SyntaxError: Unexpected token '<'` when an upload was rejected + upstream (e.g. nginx 413); the toast now shows `HTTP ` instead. - Made the media upload max size configurable via the new `MEDIA_MAX_UPLOAD_SIZE_MB` env var. - Fixed playlist share-target dropdown silently truncating to 30 tenants; it now loads every page. - Refactored InteractiveController to use a typed `InteractiveSlideActionInput` DTO; regenerated API spec and RTK types. diff --git a/assets/admin/components/util/list/toast-component/display-toast.jsx b/assets/admin/components/util/list/toast-component/display-toast.jsx index ca7dec087..5154ab64a 100644 --- a/assets/admin/components/util/list/toast-component/display-toast.jsx +++ b/assets/admin/components/util/list/toast-component/display-toast.jsx @@ -27,10 +27,19 @@ export function displayError(errorString, error) { if (error && error["hydra:description"]) { errorText = error["hydra:description"]; } - if (error && error.data) { - errorText = error.data["hydra:description"] || error.data.message; + if (error?.data && typeof error.data === "object") { + errorText = error.data["hydra:description"] || error.data.message || ""; } - if (error && error.error) { + // RTK Query couldn't JSON-parse the response — typically an HTML error page + // from nginx/php-fpm rejecting the request before Symfony (e.g. 413 when the + // upload exceeds the proxy body-size limit). Show the HTTP status instead + // of leaking the "Unexpected token '<'" SyntaxError to the user. + if (!errorText && error?.status === "PARSING_ERROR") { + errorText = error.originalStatus + ? `HTTP ${error.originalStatus}` + : "Server returned an unexpected response"; + } + if (!errorText && error?.error) { errorText = error.error; }