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.
This commit is contained in:
gorkem-bwl committed 2026-04-26 01:56:13 -04:00
1 parent 127ee5508a
commit a4f69daae7
4 files changed
+21 -11

No files matched your search

+11 -2
View File
@@ -33,11 +33,14 @@ function App() {
body: { body: {
backgroundColor: theme.palette.background.default, backgroundColor: theme.palette.background.default,
}, },
".Toastify__progress-bar, .Toastify__progress-bar--bg": { ".Toastify__progress-bar": {
height: 2, height: 2,
bottom: 0, bottom: 0,
top: "auto", top: "auto",
}, },
".Toastify__progress-bar--bg": {
display: "none",
},
}} }}
/> />
<AppLayout> <AppLayout>
@@ -53,9 +56,15 @@ function App() {
"--toastify-color-progress-dark": theme.palette.primary.main, "--toastify-color-progress-dark": theme.palette.primary.main,
"--toastify-toast-min-height": "40px", "--toastify-toast-min-height": "40px",
"--toastify-toast-padding": "8px 12px", "--toastify-toast-padding": "8px 12px",
"--toastify-toast-width": "auto",
} as CSSProperties } 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 }} progressStyle={{ height: 2 }}
/> />
</ThemeProvider> </ThemeProvider>
+5 -1
View File
@@ -57,7 +57,11 @@ export const usePost = <B = any, R = any>() => {
...config?.headers, ...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; return res.data;
} catch (err: any) { } catch (err: any) {
+3 -2
View File
@@ -4,8 +4,9 @@ export const useToast = () => {
const showToast = (message: string, options?: ToastOptions) => { const showToast = (message: string, options?: ToastOptions) => {
toast.dismiss(); toast.dismiss();
const baseStyle: React.CSSProperties = { const baseStyle: React.CSSProperties = {
whiteSpace: "pre-line", whiteSpace: "nowrap",
wordBreak: "break-word", overflow: "hidden",
textOverflow: "ellipsis",
}; };
toast(message, { toast(message, {
...options, ...options,
@@ -37,13 +37,9 @@ class NotificationController implements INotificationController {
const notification = testNotificationBodyValidation.parse(req.body); const notification = testNotificationBodyValidation.parse(req.body);
const success = await this.notificationsService.sendTestNotification(notification); const success = await this.notificationsService.sendTestNotification(notification);
if (!success) {
throw new AppError({ message: "Sending notification failed", status: 500 });
}
return res.status(200).json({ return res.status(200).json({
success: true, success,
msg: "Notification sent successfully", msg: success ? "Notification sent successfully" : "Notification could not be sent — check the destination details.",
details: { service: SERVICE_NAME }, details: { service: SERVICE_NAME },
}); });
} catch (error) { } catch (error) {