diff --git a/src/app/services/app.ts b/src/app/services/app.ts index 2d79dcc2..dc512630 100644 --- a/src/app/services/app.ts +++ b/src/app/services/app.ts @@ -89,7 +89,12 @@ export class AppService { status = 'ok'; User.logined = true; } catch (err) { - status = 'error'; + status = 'error'; // 默认错误状态 + if (err.status === 401) { + status = 'unauthorized'; + } else if (err.status === 400) { + status = 'badrequest'; + } } finally { localStorage.setItem('CheckProfile', status + ' ' + new Date().getTime()); } @@ -101,24 +106,34 @@ export class AppService { async doCheckProfile(recheck = false) { const status = await this.getProfileStatus(recheck); - if (status === 'ok') { - this.newLoginHasOpen = false; - // 重新检查时,如果好了,重启 check - if (recheck) { - this.intervalCheckLogin().then(); - } - } else { + if (['unauthorized', 'badrequest', 'error'].includes(status)) { clearInterval(this.checkIntervalId); - const ok = confirm(this._i18n.instant('LoginExpireMsg')); + const ok = confirm(this._i18n.instant(this.getErrorMsg(status))); if (ok && !this.newLoginHasOpen) { window.open('/core/auth/login/?next=/luna/', '_self'); this.newLoginHasOpen = true; } - setTimeout(() => this.doCheckProfile(true), 5 * 1000); + setTimeout(() => this.doCheckProfile(true), 5000); + this._logger.debug(`${status}, redirect to login`); + } else if (status === 'ok') { + this.newLoginHasOpen = false; + if (recheck) { + this.intervalCheckLogin().then(); + } + this._logger.debug('Profile is ok'); } return status; } + getErrorMsg(status: string) { + const messages = { + 'unauthorized': 'LoginExpireMsg', + 'badrequest': 'Bad request. The server does not understand the syntax of the request', + 'error': 'The server encountered an error while trying to process the request' + }; + return messages[status]; + } + async intervalCheckLogin(second = null, clear: boolean = false) { if (second == null) { second = this.checkSecond; diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index e17c7351..26d24b60 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -127,6 +127,8 @@ "Username@Domain": "Username@Domain", "InstallClientMsg": "JumpServer client not found, Go to download and install?", "LoginExpireMsg": "Login session expired, please re-login", + "Bad request. The server does not understand the syntax of the request": "Bad request. The server does not understand the syntax of the request", + "The server encountered an error while trying to process the request": "The server encountered an error while trying to process the request", "No permission": "No permission", "Last login": "Last login", "Log out": "Log out", diff --git a/src/assets/i18n/ja.json b/src/assets/i18n/ja.json index 9970a41b..a83b27bd 100644 --- a/src/assets/i18n/ja.json +++ b/src/assets/i18n/ja.json @@ -126,6 +126,8 @@ "Username@Domain": "ユーザー名 @ ADドメイン", "InstallClientMsg": "JumpServerクライアントがインストールされていない、今ダウンロードしてインストールしますか?", "LoginExpireMsg": "ログインが期限切れになりました。ログインし直してください", + "Bad request. The server does not understand the syntax of the request": "要求の形式が正しくありません。 サーバーはリクエストの構文を理解していません", + "The server encountered an error while trying to process the request": "サーバーがリクエストを処理しようとしたときにエラーが発生しました", "No permission": "権限がありません", "Last login": "前回ログイン", "Log out": "ログインを終了", diff --git a/src/assets/i18n/zh-hant.json b/src/assets/i18n/zh-hant.json index 50ba8ea6..dcf29afc 100644 --- a/src/assets/i18n/zh-hant.json +++ b/src/assets/i18n/zh-hant.json @@ -126,6 +126,8 @@ "Username@Domain": "使用者名稱@AD域", "InstallClientMsg": "JumpServer 用戶端沒有安裝,現在去下載安裝?", "LoginExpireMsg": "登入已過期,請重新登入", + "Bad request. The server does not understand the syntax of the request": "錯誤的請求。 服務器不理解請求的語法", + "The server encountered an error while trying to process the request": "服務器在嘗試處理請求時遇到錯誤", "No permission": "沒有權限", "Last login": "上次登入", "Log out": "退出登入", diff --git a/src/assets/i18n/zh.json b/src/assets/i18n/zh.json index d0ecebd5..37cf7a03 100644 --- a/src/assets/i18n/zh.json +++ b/src/assets/i18n/zh.json @@ -127,6 +127,8 @@ "Username@Domain": "用户名@AD域", "InstallClientMsg": "JumpServer 客户端没有安装,现在去下载安装?", "LoginExpireMsg": "登录已过期,请重新登录", + "Bad request. The server does not understand the syntax of the request": "错误的请求。 服务器不理解请求的语法", + "The server encountered an error while trying to process the request": "服务器在尝试处理请求时遇到错误", "No permission": "没有权限", "Last login": "上次登录", "Log out": "退出登录",