From cfd20703b2950379ed3fcb8b158b13c35663c2f4 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Tue, 16 Jul 2024 15:10:44 +0200 Subject: [PATCH] fix: toast error doesn't tell you what the error is (#7601) This change improves the toast error message for auth settings by preferring the message from the error's details list if it exists. If it doesn't it'll still fall back to the original error message. Before: ![image](https://github.com/user-attachments/assets/6ecb425c-7d6d-4cb9-844e-c7c2ff7088b2) After: ![image](https://github.com/user-attachments/assets/87d827a8-7f52-40c1-a2c6-ca2d1d3abfb4) --- .../api/actions/useAuthSettingsApi/useAuthSettingsApi.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/api/actions/useAuthSettingsApi/useAuthSettingsApi.ts b/frontend/src/hooks/api/actions/useAuthSettingsApi/useAuthSettingsApi.ts index c507da7fa6..cfc6fb4026 100644 --- a/frontend/src/hooks/api/actions/useAuthSettingsApi/useAuthSettingsApi.ts +++ b/frontend/src/hooks/api/actions/useAuthSettingsApi/useAuthSettingsApi.ts @@ -12,8 +12,9 @@ export const handleBadRequest = async ( if (!setErrors) return; if (res) { const data = await res.json(); - setErrors({ message: data.message }); - throw new Error(data.message); + const message = data.details?.[0]?.message ?? data.message; + setErrors({ message }); + throw new Error(message); } throw new Error();