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)); 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(); } } 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 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;