fix(campaigns): fix start_date modal — interceptor was losing structured detail

client.ts: when FastAPI detail is an object, extract .message for the error
string and preserve the full detail on enhancedError.detail so consumers
can inspect structured error payloads (e.g. 409 start_date_in_future).

CampaignDetailPage: use enhancedErr.status (not response.status) and
enhancedErr.detail (not response.data.detail) to detect 409 and show
the confirmation modal instead of the toast.
This commit is contained in:
kitos
2026-06-04 16:22:17 +02:00
parent bf3add9b09
commit 564eb406aa
2 changed files with 33 additions and 27 deletions
+14 -20
View File
@@ -98,29 +98,23 @@ export default function CampaignDetailPage() {
showToast("Campaign activated", "success");
},
onError: (err: unknown) => {
// FastAPI wraps error bodies as: { detail: string | object }
type AxiosLike = {
response?: {
status?: number;
data?: { detail?: { code?: string; message?: string } | string };
};
// The Axios interceptor (client.ts) transforms errors into enhanced Error objects
// with .status (HTTP status), .detail (raw FastAPI detail), and .message (readable string)
type EnhancedError = Error & {
status?: number;
detail?: { code?: string; message?: string } | string;
};
const axiosErr = err as AxiosLike;
const status = axiosErr?.response?.status;
const detail = axiosErr?.response?.data?.detail;
const e = err as EnhancedError;
if (status === 409 && detail && typeof detail === "object" && detail.message) {
// Future start_date show confirmation modal
setStartDateWarning(detail.message);
if (e.status === 409) {
// Future start_date show confirmation modal using the message from detail
const warningMsg =
typeof e.detail === "object" && e.detail?.message
? e.detail.message
: e.message;
setStartDateWarning(warningMsg);
} else {
// 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");
showToast(e.message || "Failed to activate campaign", "error");
}
},
});