From 1926daa3c7df4b0ec307291cfaad3ad954d1d214 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 26 Dec 2024 11:19:33 -0600 Subject: [PATCH 1/4] MastodonResponse: use .passthrough() on errorSchema Fixes https://gitlab.com/soapbox-pub/soapbox/-/issues/1801 --- src/api/MastodonResponse.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/MastodonResponse.ts b/src/api/MastodonResponse.ts index b85fe7c49..6bd1a1ace 100644 --- a/src/api/MastodonResponse.ts +++ b/src/api/MastodonResponse.ts @@ -81,7 +81,7 @@ export class MastodonResponse extends Response { z.string(), z.object({ error: z.string(), description: z.string() }).array(), ).optional(), - }); + }).passthrough(); } } From 3158e0a16abc898c7229d899b87860b54f21dfdd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 26 Dec 2024 11:26:58 -0600 Subject: [PATCH 2/4] showAlertForError: fallthrough when response.error() fails --- src/toast.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/toast.tsx b/src/toast.tsx index 3011a9b87..ee2e4d6ae 100644 --- a/src/toast.tsx +++ b/src/toast.tsx @@ -57,9 +57,13 @@ async function showAlertForError(networkError: HTTPError): Promise { return; } - const data = await response.error(); - if (data) { - return error(data.error); + try { + const data = await response.error(); + if (data) { + return error(data.error); + } + } catch { + // fallthrough } const message = httpErrorMessages.find((httpError) => httpError.code === status)?.description; From 39065bc1af6bc08cf5547c9fdb867da3dfd5dd7a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 27 Dec 2024 12:13:58 -0600 Subject: [PATCH 3/4] compose: log upload errors to console --- src/actions/compose.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/actions/compose.ts b/src/actions/compose.ts index 7bce18894..0c3bd2a68 100644 --- a/src/actions/compose.ts +++ b/src/actions/compose.ts @@ -384,7 +384,10 @@ const uploadCompose = (composeId: string, files: FileList, intl: IntlShape) => f, intl, (data) => dispatch(uploadComposeSuccess(composeId, data, f)), - (error) => dispatch(uploadComposeFail(composeId, error)), + (error) => { + console.error(error); + dispatch(uploadComposeFail(composeId, error)); + }, (e: ProgressEvent) => { progress[i] = e.loaded; dispatch(uploadComposeProgress(composeId, progress.reduce((a, v) => a + v, 0), e.total)); From 715c961fff8ec72226a1abe2945a95132ee04fb2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 27 Dec 2024 12:14:24 -0600 Subject: [PATCH 4/4] Polyfill Promise.withResolvers Fixes: https://gitlab.com/soapbox-pub/soapbox/-/issues/1802 --- src/main.tsx | 2 ++ src/polyfill/Promise.withResolvers.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/polyfill/Promise.withResolvers.ts diff --git a/src/main.tsx b/src/main.tsx index 9204d45bd..61ef3b99a 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,3 +1,5 @@ +import 'soapbox/polyfill/Promise.withResolvers.ts'; + import { enableMapSet } from 'immer'; import { createRoot } from 'react-dom/client'; diff --git a/src/polyfill/Promise.withResolvers.ts b/src/polyfill/Promise.withResolvers.ts new file mode 100644 index 000000000..918bf4504 --- /dev/null +++ b/src/polyfill/Promise.withResolvers.ts @@ -0,0 +1,14 @@ +if (!Promise.withResolvers) { + Promise.withResolvers = function withResolvers(): PromiseWithResolvers { + + let resolve: (value: T | PromiseLike) => void; + let reject: (reason?: any) => void; + + const promise = new this((_resolve, _reject) => { + resolve = _resolve; + reject = _reject; + }); + + return { resolve: resolve!, reject: reject!, promise }; + }; +} \ No newline at end of file