From 910c198545b63a4709e40521e0ae4b457b936079 Mon Sep 17 00:00:00 2001 From: kitos Date: Thu, 4 Jun 2026 15:57:54 +0200 Subject: [PATCH] fix(campaigns): correct Axios error parsing in activateMutation FastAPI wraps error bodies as {detail: string | object}, not at the top level. Was reading data.message instead of data.detail.message, causing [object Object] in the toast for all non-409 errors. Now correctly extracts: - 409 with object detail -> start_date warning modal - Other errors with string detail -> readable toast message - Other errors with object detail -> detail.message in toast Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/CampaignDetailPage.tsx | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/CampaignDetailPage.tsx b/frontend/src/pages/CampaignDetailPage.tsx index d1f1ec2..3a9e4e4 100644 --- a/frontend/src/pages/CampaignDetailPage.tsx +++ b/frontend/src/pages/CampaignDetailPage.tsx @@ -98,12 +98,29 @@ export default function CampaignDetailPage() { showToast("Campaign activated", "success"); }, onError: (err: unknown) => { - // 409 = future start_date warning → show confirmation modal instead of toast - const axiosErr = err as { response?: { status?: number; data?: { message?: string; start_date?: string } } }; - if (axiosErr?.response?.status === 409 && axiosErr.response.data?.message) { - setStartDateWarning(axiosErr.response.data.message); + // FastAPI wraps error bodies as: { detail: string | object } + type AxiosLike = { + response?: { + status?: number; + data?: { detail?: { code?: string; message?: string } | string }; + }; + }; + const axiosErr = err as AxiosLike; + const status = axiosErr?.response?.status; + const detail = axiosErr?.response?.data?.detail; + + if (status === 409 && detail && typeof detail === "object" && detail.message) { + // Future start_date → show confirmation modal + setStartDateWarning(detail.message); } else { - showToast((err as Error).message, "error"); + // Any other error → extract readable message from FastAPI detail + const msg = + typeof detail === "string" + ? detail + : typeof detail === "object" && detail?.message + ? detail.message + : "Failed to activate campaign"; + showToast(msg, "error"); } }, });