show friendly error when user registration is disabled

This commit is contained in:
MaysWind
2020-10-27 00:56:12 +08:00
parent 56d7834f54
commit 046d6d7230
4 changed files with 17 additions and 0 deletions
+1
View File
@@ -37,6 +37,7 @@ func PrintErrorResult(c *core.Context, err *errs.Error) {
"success": false,
"errorCode": err.Code(),
"errorMessage": errorMessage,
"path": c.Request.URL.Path,
})
}
+12
View File
@@ -1,5 +1,11 @@
import { defaultLanguage, allLanguages } from '../locales/index.js'
const apiNotFoundErrorCode = 100001;
const specifiedApiNotFoundErrors = {
'/api/register.json': {
message: 'User registration is disabled'
}
};
const validatorErrorCode = 200000;
const parameterizedErrors = [
{
@@ -134,6 +140,12 @@ export function getI18nOptions() {
}
export function getLocalizedError(error) {
if (error.errorCode === apiNotFoundErrorCode && specifiedApiNotFoundErrors[error.path]) {
return {
message: `${specifiedApiNotFoundErrors[error.path].message}`
};
}
if (error.errorCode !== validatorErrorCode) {
return {
message: `error.${error.errorMessage}`
+2
View File
@@ -6,6 +6,7 @@ export default {
},
'error': {
'system error': 'System Error',
'api not found': 'Failed to request api',
'incomplete or incorrect submission': 'Incomplete or incorrect submission',
'operation failed': 'Operation failed',
'nothing will be updated': 'Nothing will be updated',
@@ -92,6 +93,7 @@ export default {
'Language': 'Language',
'You have been successfully registered': 'You have been successfully registered',
'Unable to sign up': 'Unable to sign up',
'User registration is disabled': 'User registration is disabled',
'Log Out': 'Log Out',
'Are you sure you want to log out?': 'Are you sure you want to log out?',
'Unable to logout': 'Unable to logout',
+2
View File
@@ -6,6 +6,7 @@ export default {
},
'error': {
'system error': '系统错误',
'api not found': '接口调用失败',
'incomplete or incorrect submission': '提交不完整或不正确',
'operation failed': '操作失败',
'nothing will be updated': '没有内容更新',
@@ -92,6 +93,7 @@ export default {
'Language': '语言',
'You have been successfully registered': '注册成功',
'Unable to sign up': '无法注册',
'User registration is disabled': '用户注册已禁用',
'Log Out': '退出登录',
'Are you sure you want to log out?': '您确定是否要退出登录?',
'Unable to logout': '无法退出登录',