fix(campaigns): correct Axios error parsing in activateMutation
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user