-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from sj-distributor/enhance-error-message
Enhance error message
- Loading branch information
Showing
6 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
DUPLICATE_CAMERA: "DuplicateCamera", | ||
DATABASE_ERROR: "DatabaseError", | ||
ERROR_CAMERA: "ErrorCamera", | ||
INSUFFICIENT_RESOURCES: "InsufficientResources", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import KEYS from "../keys/error-message-keys"; | ||
|
||
export default { | ||
en: { | ||
[KEYS.DUPLICATE_CAMERA]: "Reduplicative camera,please check and resubmit", | ||
[KEYS.DATABASE_ERROR]: "gateway database error,please try again later", | ||
[KEYS.ERROR_CAMERA]: | ||
"camera not found or not online,please try again later", | ||
[KEYS.INSUFFICIENT_RESOURCES]: "No node free,please try again later", | ||
}, | ||
ch: { | ||
[KEYS.DUPLICATE_CAMERA]: "存在重复camera,請檢查後重新提交", | ||
[KEYS.DATABASE_ERROR]: "當前数据库异常,請稍候重試", | ||
[KEYS.ERROR_CAMERA]: "當前摄像头信息错误或离线,請稍候重試", | ||
[KEYS.INSUFFICIENT_RESOURCES]: "當前资源不够,請稍候重試", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import KEYS from "@/i18n/language/keys/error-message-keys"; | ||
import i18n from "i18next"; | ||
|
||
const ERROR_KEYWORDS = { | ||
DUPLICATE_CAMERA: "Reduplicative camera", | ||
DATABASE_ERROR: "gateway database error", | ||
ERROR_CAMERA: "camera not found or not online", | ||
INSUFFICIENT_RESOURCES: "insufficient resource", | ||
}; | ||
|
||
export const getErrorMessage = (error: string) => { | ||
const { t } = i18n; | ||
|
||
const ERROR_MESSAGES = { | ||
DUPLICATE_CAMERA: t(KEYS.DUPLICATE_CAMERA, { ns: "errorMessage" }), | ||
DATABASE_ERROR: t(KEYS.DATABASE_ERROR, { ns: "errorMessage" }), | ||
ERROR_CAMERA: t(KEYS.ERROR_CAMERA, { ns: "errorMessage" }), | ||
INSUFFICIENT_RESOURCES: t(KEYS.INSUFFICIENT_RESOURCES, { | ||
ns: "errorMessage", | ||
}), | ||
}; | ||
|
||
for (const [key, keyword] of Object.entries(ERROR_KEYWORDS)) { | ||
if (error.includes(keyword)) { | ||
return ERROR_MESSAGES[key as keyof typeof ERROR_MESSAGES]; | ||
} | ||
} | ||
return error; | ||
}; |