fix: localize customer-facing errors
Deploy olons-server production / deploy (push) Successful in 1m48s
Deploy olons-server production / deploy (push) Successful in 1m48s
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package httpapi
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestLocalizedAPIErrorMessage(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
reason string
|
||||
message string
|
||||
want string
|
||||
}{
|
||||
{name: "login password", reason: "LOGIN_PASSWORD_INVALID", message: "login password is invalid", want: "登录密码不正确"},
|
||||
{name: "known validation", reason: "PHONE_INVALID_FORMAT", message: "validation failed", want: "手机号码格式不正确"},
|
||||
{name: "preserve chinese", reason: "CUSTOM_REASON", message: "自定义中文提示", want: "自定义中文提示"},
|
||||
{name: "hide unknown english", reason: "CUSTOM_REASON", message: "unexpected dependency error", want: "请求失败,请稍后重试"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := localizedAPIErrorMessage(test.reason, test.message); got != test.want {
|
||||
t.Fatalf("localizedAPIErrorMessage() = %q, want %q", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user