feat: add enableErrorMask config

This commit is contained in:
Yang Luo 2024-08-23 22:19:17 +08:00
parent 986dcbbda1
commit 0b8be016c5
2 changed files with 8 additions and 0 deletions

View File

@ -21,6 +21,7 @@ originFrontend =
staticBaseUrl = "https://cdn.casbin.org"
isDemoMode = false
batchSize = 100
enableErrorMask = false
enableGzip = true
ldapServerPort = 389
radiusServerPort = 1812

View File

@ -45,6 +45,13 @@ func (c *ApiController) ResponseOk(data ...interface{}) {
// ResponseError ...
func (c *ApiController) ResponseError(error string, data ...interface{}) {
enableErrorMask := conf.GetConfigBool("enableErrorMask")
if enableErrorMask {
if strings.HasPrefix(error, "The user: ") && strings.HasSuffix(error, " doesn't exist") || strings.HasPrefix(error, "用户: ") && strings.HasSuffix(error, "不存在") {
error = c.T("check:password or code is incorrect")
}
}
resp := &Response{Status: "error", Msg: error}
c.ResponseJsonData(resp, data...)
}