fix: do not log CSRF error in Electron environments (#21054)

Closes #20914
This commit is contained in:
Ehab Younes
2025-12-08 16:24:59 +03:00
committed by GitHub
parent 4d15b30a63
commit 52243557a2
+6 -3
View File
@@ -2783,15 +2783,18 @@ function getConfiguredAxiosInstance(): AxiosInstance {
if (process.env.NODE_ENV === "development") {
// Development mode uses a hard-coded CSRF token
instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken;
instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken;
tokenMetadataElement.setAttribute("content", csrfToken);
} else {
instance.defaults.headers.common["X-CSRF-TOKEN"] =
tokenMetadataElement.getAttribute("content") ?? "";
}
} else {
// Do not write error logs if we are in a FE unit test.
if (!process.env.JEST_WORKER_ID && !process.env.VITEST) {
// Do not write error logs if we are in a FE unit test or if there is no document (e.g., Electron)
if (
typeof document !== "undefined" &&
!process.env.JEST_WORKER_ID &&
!process.env.VITEST
) {
console.error("CSRF token not found");
}
}