From ca5f4ad8a06b05ab2393369515eb0948e0bba0b0 Mon Sep 17 00:00:00 2001 From: Jesse-Ma <24167796@qq.com> Date: Mon, 5 Dec 2022 13:18:12 +0800 Subject: [PATCH] error message --- src/App.vue | 5 --- src/api/note.js | 14 +++++++-- src/i18n/config/en.js | 4 ++- src/i18n/config/zh.js | 4 ++- src/router/index.js | 20 +++++++++++- src/views/EditNote.vue | 60 +++++++++++++++++++++++++----------- src/views/ErrorNote.vue | 21 ------------- src/views/ErrorView.vue | 5 +-- src/views/InvalidateNote.vue | 4 +-- src/views/ViewNote.vue | 27 +++++++++++++--- 10 files changed, 106 insertions(+), 58 deletions(-) delete mode 100644 src/views/ErrorNote.vue diff --git a/src/App.vue b/src/App.vue index 3607c4b..d5dd386 100644 --- a/src/App.vue +++ b/src/App.vue @@ -38,11 +38,6 @@ body { font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; } -#nprogress .bar { - background: red !important; -} - - .showBlock { display: block; } diff --git a/src/api/note.js b/src/api/note.js index 3335f20..c5899f9 100644 --- a/src/api/note.js +++ b/src/api/note.js @@ -68,13 +68,23 @@ export function getNoteBlob(key) { export function getNoteMeta(key) { let url = servicePath + "/note/" + key + "/noteMeta"; - let noteMeta = ajaxGet(url); + let noteMeta = null; + try { + noteMeta = ajaxGet(url); + } catch (error) { + console.log(error); + } return noteMeta; } export function getKeyMeta() { let url = servicePath + "/note/keyMeta"; - let keyMeta = ajaxGet(url); + let keyMeta = null; + try { + keyMeta = ajaxGet(url); + } catch (error) { + console.log(error); + } return keyMeta; } diff --git a/src/i18n/config/en.js b/src/i18n/config/en.js index c1a2fb3..d940c52 100644 --- a/src/i18n/config/en.js +++ b/src/i18n/config/en.js @@ -22,7 +22,9 @@ const en = { "100003": "Deleted!", "100004": "Expired!", "100005": "Not Available!", - "100006": "100006", + "100006": "Server Unavailable!", + "100011": "Empty Note!", + "100012": "Too Large, Beyond 200K!", } }; export default en; diff --git a/src/i18n/config/zh.js b/src/i18n/config/zh.js index 5ec596d..8ea8ffe 100644 --- a/src/i18n/config/zh.js +++ b/src/i18n/config/zh.js @@ -22,7 +22,9 @@ const zh = { "100003": "内容已删除!", "100004": "内容已过期!", "100005": "内容不存在!", - "100006": "100006", + "100006": "服务器不可用!", + "100011": "内容为空!", + "100012": "内容过大,超过200K!", } }; export default zh; diff --git a/src/router/index.js b/src/router/index.js index 532a045..0731f33 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -27,6 +27,10 @@ function getErrorMetaParam() { } function getNoteView() { + if(errorMeta){ + return; + } + let path = location.pathname; let key = path.substring(1, path.length); @@ -49,8 +53,14 @@ function getNoteView() { //set noteMeta noteMeta = getNoteMeta(key); + //server error + if (!noteMeta) { + errorMeta = 100006; + return InvalidateNote; + } + //invalidated key - if (!noteMeta || !noteMeta.key) { + if (!noteMeta.key) { errorMeta = 100002; return InvalidateNote; } @@ -105,6 +115,13 @@ function getHomeRedirect() { //setKeyMeta keyMeta = getKeyMeta(); + + // server error + if (!keyMeta) { + errorMeta = 100006; + return "/invalidatenote"; + } + return "/" + keyMeta.key; } @@ -114,6 +131,7 @@ const routes = [ name: "home", redirect: getHomeRedirect(), }, + { path: "/invalidatenote", component: InvalidateNote }, { path: "/:name([a-z0-9]{1,20})", name: "note", diff --git a/src/views/EditNote.vue b/src/views/EditNote.vue index 89a36b7..0a8cffc 100644 --- a/src/views/EditNote.vue +++ b/src/views/EditNote.vue @@ -149,7 +149,7 @@
+ {{ errorInfo }} +
++ +
+