Unverified Commit 1c45d744 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Optimization][web] Optimize login page prompts (#3407)

parent 29cbffa2
......@@ -23,7 +23,6 @@ import {
setKeyToLocalStorage,
setLocalThemeToStorage
} from '@/utils/function';
import { l } from '@/utils/intl';
import { WarningMessageAsync } from '@/utils/messages';
import { history } from '@@/core/history';
......@@ -36,9 +35,9 @@ export const gotoRedirectUrl = () => {
}, 10);
};
export const redirectToLogin = async () => {
export const redirectToLogin = (tipMsg: string) => {
//todo: 使用模态框提示, 但是目前会重复弹出,原因是接口每次都会调用,所以会出现重复弹出
await WarningMessageAsync(l('login.token.error'));
WarningMessageAsync(tipMsg);
window.location.href = '/#/user/login';
};
......
......@@ -74,7 +74,7 @@ const Login: React.FC = () => {
const currentTime = Date.now();
timeRemaining = expirationTime - currentTime;
// use setInterval to set a timer
timer = setInterval(() => redirectToLogin(), timeRemaining);
timer = setInterval(() => redirectToLogin(l('login.token.error')), timeRemaining);
}
return () => {
clearTimeout(timer);
......@@ -141,7 +141,7 @@ const Login: React.FC = () => {
setLocalStorageOfToken(JSON.stringify(res));
} else {
// 如果没有获取到token信息,直接跳转到登录页
redirectToLogin();
redirectToLogin(l('login.token.error'));
}
});
}
......
......@@ -230,12 +230,22 @@ const ResourceOverView: React.FC<connect> = (props) => {
const handleModalSubmit = async (value: Partial<ResourceInfo>) => {
const { id: pid } = resourceState.rightClickedNode;
if (editModal === 'createFolder') {
await handleOption(API_CONSTANTS.RESOURCE_CREATE_FOLDER, l('right.menu.createFolder'), {
...value,
pid
}, ()=> handleModalCancel());
await handleOption(
API_CONSTANTS.RESOURCE_CREATE_FOLDER,
l('right.menu.createFolder'),
{
...value,
pid
},
() => handleModalCancel()
);
} else if (editModal === 'rename') {
await handleOption(API_CONSTANTS.RESOURCE_RENAME, l('right.menu.rename'), { ...value, pid },()=> handleModalCancel());
await handleOption(
API_CONSTANTS.RESOURCE_RENAME,
l('right.menu.rename'),
{ ...value, pid },
() => handleModalCancel()
);
}
};
const handleUploadCancel = async () => {
......
......@@ -31,7 +31,9 @@ enum ErrorCode {
ERROR = 1,
EXCEPTION = 5,
PARAMS_ERROR = 6,
AUTHORIZE_ERROR = 7
AUTHORIZE_ERROR = 7,
SERVER_ERROR = 504,
UNAUTHORIZED = 401
}
// Response data format agreed upon with the backend
......@@ -88,6 +90,13 @@ export const errorConfig: RequestConfig = {
// Error reception and handling
errorHandler: (error: any, opts: any) => {
if (opts?.skipErrorHandler) throw error;
function processNotification(error: any, isEnableTips: string = 'false') {
if (getValueFromLocalStorage(ENABLE_MODEL_TIP) == isEnableTips) {
ErrorNotification(error.message, error.code);
}
}
//The error thrown by our errorThrower.
if (error.name === 'BizError') {
const errorInfo: ResponseStructure = error.info;
......@@ -97,12 +106,14 @@ export const errorConfig: RequestConfig = {
} else if (error.response) {
//The request was successfully sent and the server also responded with a status code, but the status code exceeded the range of 2xx
//Authentication error, redirect to login page
if (error.response.status === 401) {
redirectToLogin();
if (error.response.status === ErrorCode.UNAUTHORIZED) {
redirectToLogin(error.message);
} else if (error.response.status === ErrorCode.SERVER_ERROR) {
processNotification(error);
//Note: when the server is not available or the network is disconnected, redirect to login page
redirectToLogin(error.message);
} else {
if (getValueFromLocalStorage(ENABLE_MODEL_TIP) == 'true') {
ErrorNotification(error.message, error.code);
}
processNotification(error, 'true');
}
} else if (error.request) {
//The request has been successfully initiated, but no response has been received
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment