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:
@@ -64,15 +64,27 @@ client.interceptors.response.use(
|
||||
}
|
||||
}
|
||||
|
||||
// Extract error message from response
|
||||
// Extract error message — detail can be a string or a structured object
|
||||
const rawDetail = error.response?.data?.detail;
|
||||
const message =
|
||||
error.response?.data?.detail ||
|
||||
error.message ||
|
||||
"An unexpected error occurred";
|
||||
typeof rawDetail === "string"
|
||||
? rawDetail
|
||||
: typeof rawDetail === "object" && rawDetail !== null && (rawDetail as { message?: string }).message
|
||||
? (rawDetail as { message: string }).message
|
||||
: error.message || "An unexpected error occurred";
|
||||
|
||||
const enhancedError = new Error(message);
|
||||
(enhancedError as Error & { status?: number }).status = status;
|
||||
(enhancedError as Error & { code?: string }).code = error.response?.data?.code;
|
||||
const enhancedError = new Error(message) as Error & {
|
||||
status?: number;
|
||||
code?: string;
|
||||
detail?: unknown;
|
||||
};
|
||||
enhancedError.status = status;
|
||||
// Preserve the full detail object so consumers can inspect it (e.g. for modal flows)
|
||||
enhancedError.detail = rawDetail;
|
||||
enhancedError.code =
|
||||
typeof rawDetail === "object" && rawDetail !== null
|
||||
? (rawDetail as { code?: string }).code
|
||||
: error.response?.data?.code;
|
||||
|
||||
return Promise.reject(enhancedError);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user