From 035d7a0a32b111d409936f113b37f02110127da2 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Thu, 21 Nov 2024 20:13:04 -0300 Subject: [PATCH] fix: use response error from the backend if available --- src/features/admin/manage-ditto-server.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/features/admin/manage-ditto-server.tsx b/src/features/admin/manage-ditto-server.tsx index 6e457108f..54e171a22 100644 --- a/src/features/admin/manage-ditto-server.tsx +++ b/src/features/admin/manage-ditto-server.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { uploadMedia } from 'soapbox/actions/media.ts'; +import { HTTPError } from 'soapbox/api/HTTPError.ts'; import StillImage from 'soapbox/components/still-image.tsx'; import { Button } from 'soapbox/components/ui/button.tsx'; import { Column } from 'soapbox/components/ui/column.tsx'; @@ -93,7 +94,16 @@ const ManageDittoServer: React.FC = () => { toast.success(messages.submit_success); }, onError: async (err) => { - toast.error(err.message); // generic error message, not the one returned by the backend + if (err instanceof HTTPError) { + try { + const { error } = await err.response.json(); + if (typeof error === 'string') { + toast.error(error); + return; + } + } catch { /* empty */ } + toast.error(err.message); + } }, }); };