From a4f69daae7a2fa6ceb7b91373211b7b919a85830 Mon Sep 17 00:00:00 2001 From: gorkem-bwl Date: Sun, 26 Apr 2026 01:56:13 -0400 Subject: [PATCH] fix: surface notification test failures cleanly instead of as 500s Server-side, return 200 with success: false and a friendly message when sendTestNotification reports failure (the underlying call already swallows the error); reserve real 500s for unexpected exceptions. Client-side, teach usePost to honour the response body's success flag so success:false flips the toast to error without throwing through axios. Also tidy the toast container: drop icons, no wrapping, single-line ellipsis with a sensible max-width that hugs short messages. --- client/src/App.tsx | 13 +++++++++++-- client/src/Hooks/UseApi.ts | 6 +++++- client/src/Hooks/UseToast.ts | 5 +++-- server/src/controllers/notificationController.ts | 8 ++------ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 6fff55eca..5a1a36455 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -33,11 +33,14 @@ function App() { body: { backgroundColor: theme.palette.background.default, }, - ".Toastify__progress-bar, .Toastify__progress-bar--bg": { + ".Toastify__progress-bar": { height: 2, bottom: 0, top: "auto", }, + ".Toastify__progress-bar--bg": { + display: "none", + }, }} /> @@ -53,9 +56,15 @@ function App() { "--toastify-color-progress-dark": theme.palette.primary.main, "--toastify-toast-min-height": "40px", "--toastify-toast-padding": "8px 12px", + "--toastify-toast-width": "auto", } as CSSProperties } - toastStyle={{ minHeight: 40, padding: "8px 12px" }} + toastStyle={{ + minHeight: 40, + padding: "8px 12px", + width: "auto", + maxWidth: "min(560px, calc(100vw - 32px))", + }} progressStyle={{ height: 2 }} /> diff --git a/client/src/Hooks/UseApi.ts b/client/src/Hooks/UseApi.ts index 84fd1b547..543a9f165 100644 --- a/client/src/Hooks/UseApi.ts +++ b/client/src/Hooks/UseApi.ts @@ -57,7 +57,11 @@ export const usePost = () => { ...config?.headers, }, }); - toastSuccess(res.data?.msg || "Operation successful"); + if (res.data?.success === false) { + toastError(res.data?.msg || "Operation failed"); + } else { + toastSuccess(res.data?.msg || "Operation successful"); + } return res.data; } catch (err: any) { diff --git a/client/src/Hooks/UseToast.ts b/client/src/Hooks/UseToast.ts index 8823aa675..72e7b18c9 100644 --- a/client/src/Hooks/UseToast.ts +++ b/client/src/Hooks/UseToast.ts @@ -4,8 +4,9 @@ export const useToast = () => { const showToast = (message: string, options?: ToastOptions) => { toast.dismiss(); const baseStyle: React.CSSProperties = { - whiteSpace: "pre-line", - wordBreak: "break-word", + whiteSpace: "nowrap", + overflow: "hidden", + textOverflow: "ellipsis", }; toast(message, { ...options, diff --git a/server/src/controllers/notificationController.ts b/server/src/controllers/notificationController.ts index 0a49cbdb1..301c15446 100644 --- a/server/src/controllers/notificationController.ts +++ b/server/src/controllers/notificationController.ts @@ -37,13 +37,9 @@ class NotificationController implements INotificationController { const notification = testNotificationBodyValidation.parse(req.body); const success = await this.notificationsService.sendTestNotification(notification); - if (!success) { - throw new AppError({ message: "Sending notification failed", status: 500 }); - } - return res.status(200).json({ - success: true, - msg: "Notification sent successfully", + success, + msg: success ? "Notification sent successfully" : "Notification could not be sent — check the destination details.", details: { service: SERVICE_NAME }, }); } catch (error) {