fix: fix an issue with forbidden api actions causing logout
* Revert "fix: mark all 4xx api failures as auth failure (#4690)"
This reverts commit
* describe isAuthFailure.
@@ -8,10 +8,23 @@ import { DetError, DetErrorOptions, ErrorLevel, ErrorType, isDetError } from './
export const getResponseStatus = (e: any): number | undefined => {
return e?.response?.status || e?.status;
};
+/**
+ * Determines whether an exception is the result of a nework error
+ * due to the server not being able to authenticate the request/user.
+ * If this is the case, this can lead to the client being logged out and
+ * redirected to the login page.
+ * @param e
+ * @param supportExternalAuth
+ * @returns
+ */
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
export const isAuthFailure = (e: any, supportExternalAuth = false): boolean => {
const status = getResponseStatus(e) ?? 0;
- return (supportExternalAuth && status === 500) || (status >= 400 && status < 500);
+ const authFailureStatuses = [
+ 401, // Unauthorized
+ ];
+ if (supportExternalAuth) authFailureStatuses.push(500);
+ return authFailureStatuses.includes(status);
};
const isApiResponse = (o: unknown): o is Response => {
return o instanceof Response;
