Skip to content

Commit

Permalink
refactor(i18n): translate more error codes (#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious authored Jan 13, 2023
1 parent 3114d70 commit 9ad109a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
27 changes: 26 additions & 1 deletion packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@
"the-room-is-not-over-yet": "The room is not over yet",
"unsupported-login-platforms": "Unsupported login platform",
"user-does-not-exist": "User does not exist",
"user-room-list-is-not-empty": "Your room list is not empty, please quit joined rooms",
"user-already-binding": "You have already bound the account",
"voucher-expired": "The credentials have expired, please log in again",
"check-updates": "Check updates",
"exit-replay": "Exit replay",
Expand Down Expand Up @@ -569,5 +571,28 @@
"has-turn-off-camera": "Camera has been turned off",
"has-turn-off-mic": "Microphone has been turned off",
"teacher-has-turn-off-camera": "Teacher has turned your camera off",
"teacher-has-turn-off-mic": "Teacher has turned your microphone off"
"teacher-has-turn-off-mic": "Teacher has turned your microphone off",
"upload-concurrent-limit": "You have reached the upload concurrent limit",
"file-is-too-big": "File is too big",
"file-not-found": "File not found",
"file-already-exists": "File already exists",
"directory-not-exists": "Directory not found",
"directory-already-exists": "Directory already exists",
"file-is-converted": "File is already converted",
"convert-failed": "Failed to convert the file",
"file-is-converting": "File is in converting",
"convert-is-pending": "Your conversion process is in queue",
"convert-step-not-none": "File is in converting or converted",
"convert-step-not-converting": "File is not in converting",
"login-github-suspended": "The GitHub App has been suspended",
"login-github-url-is-wrong": "The GitHub redirect url is wrong",
"login-github-access-denied": "The GitHub App access is denied",
"exhaustive-attack": "Your request is too often, please try again later",
"request-signature-incorrect": "Request signature is incorrect",
"non-compliant": "Please check your words",
"unsupported-operation": "Unsupported operation",
"censorship-failed": "Your request had been denied because of legal reasons",
"oauth-uuid-not-found": "OAuth UUID not found",
"oauth-client-id-not-found": "OAuth client id not found",
"oauth-secret-uuid-not-found": "OAuth secret not found"
}
27 changes: 26 additions & 1 deletion packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@
"periodic-rooms-have-ended": "周期性房间已结束",
"periodic-sub-rooms-do-not-exist": "周期性子房间不存在",
"user-does-not-exist": "用户不存在",
"user-room-list-is-not-empty": "用户房间列表不为空",
"user-already-binding": "用户已绑定",
"replay-does-not-exist": "回放不存在",
"check-updates": "检查更新",
"latest-version-tips": "当前已是最新版本",
Expand Down Expand Up @@ -569,5 +571,28 @@
"has-turn-off-camera": "已关闭该学生的摄像头",
"has-turn-off-mic": "已关闭该学生的麦克风",
"teacher-has-turn-off-camera": "老师已关闭你的摄像头",
"teacher-has-turn-off-mic": "老师已关闭你的麦克风"
"teacher-has-turn-off-mic": "老师已关闭你的麦克风",
"upload-concurrent-limit": "上传并发数达到上限",
"file-is-too-big": "文件过大",
"file-not-found": "文件不存在",
"file-already-exists": "文件已存在",
"directory-not-exists": "文件夹不存在",
"directory-already-exists": "文件夹已存在",
"file-is-converted": "文件已转码",
"convert-failed": "转码失败",
"file-is-converting": "文件正在转码",
"convert-is-pending": "转码任务已提交",
"convert-step-not-none": "文件正在转码或已转码",
"convert-step-not-converting": "文件不在转码",
"login-github-suspended": "{{appName}} 的 GitHub App 已被冻结",
"login-github-url-is-wrong": "GitHub 的回调地址不正确",
"login-github-access-denied": "GitHub 授权失败",
"exhaustive-attack": "你的操作过于频繁,请稍后再试",
"request-signature-incorrect": "请求签名不正确",
"non-compliant": "有不规范用词请修改",
"unsupported-operation": "不支持的操作",
"censorship-failed": "审核失败",
"oauth-uuid-not-found": "未找到该 OAuth App",
"oauth-client-id-not-found": "未找到该 OAuth App client",
"oauth-secret-uuid-not-found": "未找到该 OAuth 密钥"
}
27 changes: 25 additions & 2 deletions packages/flat-server-api/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export enum RequestErrorCode {
NeedLoginAgain,
UnsupportedPlatform,
JWTSignFailed,
ExhaustiveAttack,
RequestSignatureIncorrect,
NonCompliant,
UnsupportedOperation,

RoomNotFound = 200000,
RoomIsEnded,
Expand All @@ -25,6 +29,8 @@ export enum RequestErrorCode {
PeriodicSubRoomHasRunning,

UserNotFound = 400000,
UserRoomListNotEmpty, // occurs when delete account, user must have quitted all running rooms
UserAlreadyBinding, // already bound, should unbind first

RecordNotFound = 500000,

Expand All @@ -50,6 +56,12 @@ export enum RequestErrorCode {
SMSVerificationCodeInvalid = 110000, // verification code invalid
SMSAlreadyExist, // phone already exist
SMSAlreadyBinding, // phone are binding by other users

CensorshipFailed = 120000, // censorship failed

OAuthUUIDNotFound = 130000, // oauth uuid not found
OAuthClientIDNotFound, // oauth client id not found
OAuthSecretUUIDNotFound, // oauth secret uuid not found
}

export const RequestErrorMessage = {
Expand All @@ -69,6 +81,10 @@ export const RequestErrorMessage = {
[RequestErrorCode.NeedLoginAgain]: "voucher-expired",
[RequestErrorCode.UnsupportedPlatform]: "unsupported-login-platforms",
[RequestErrorCode.JWTSignFailed]: "authentication-information-verification-failed",
[RequestErrorCode.ExhaustiveAttack]: "exhaustive-attack",
[RequestErrorCode.RequestSignatureIncorrect]: "request-signature-incorrect",
[RequestErrorCode.NonCompliant]: "non-compliant",
[RequestErrorCode.UnsupportedOperation]: "unsupported-operation",

[RequestErrorCode.RoomNotFound]: "room-does-not-exist",
[RequestErrorCode.RoomIsEnded]: "the-room-has-ended",
Expand All @@ -82,21 +98,22 @@ export const RequestErrorMessage = {
[RequestErrorCode.PeriodicSubRoomHasRunning]: "periodic-sub-rooms-do-not-exist",

[RequestErrorCode.UserNotFound]: "user-does-not-exist",
[RequestErrorCode.UserRoomListNotEmpty]: "user-room-list-is-not-empty",
[RequestErrorCode.UserAlreadyBinding]: "user-already-binding",

[RequestErrorCode.RecordNotFound]: "replay-does-not-exist",

[RequestErrorCode.SMSVerificationCodeInvalid]: "login-phone-verification-code-invalid",
[RequestErrorCode.SMSAlreadyExist]: "login-phone-already-exist",
[RequestErrorCode.SMSAlreadyBinding]: "phone-already-binding",

// TODO: translate messages below
[RequestErrorCode.UploadConcurrentLimit]: "upload-concurrent-limit",
[RequestErrorCode.NotEnoughTotalUsage]: "total-usage-is-full",
[RequestErrorCode.FileSizeTooBig]: "file-is-too-big",
[RequestErrorCode.FileNotFound]: "file-not-found",
[RequestErrorCode.FileExists]: "file-already-exists",
[RequestErrorCode.DirectoryNotExists]: "directory-not-exists",
[RequestErrorCode.DirectoryAlreadyExists]: "convert-already-exists",
[RequestErrorCode.DirectoryAlreadyExists]: "directory-already-exists",

[RequestErrorCode.FileIsConverted]: "file-is-converted",
[RequestErrorCode.FileConvertFailed]: "convert-failed",
Expand All @@ -108,6 +125,12 @@ export const RequestErrorMessage = {
[RequestErrorCode.LoginGithubSuspended]: "login-github-suspended",
[RequestErrorCode.LoginGithubURLMismatch]: "login-github-url-is-wrong",
[RequestErrorCode.LoginGithubAccessDenied]: "login-github-access-denied",

[RequestErrorCode.CensorshipFailed]: "censorship-failed",

[RequestErrorCode.OAuthUUIDNotFound]: "oauth-uuid-not-found",
[RequestErrorCode.OAuthClientIDNotFound]: "oauth-client-id-not-found",
[RequestErrorCode.OAuthSecretUUIDNotFound]: "oauth-secret-uuid-not-found",
};

export class ServerRequestError extends Error {
Expand Down

0 comments on commit 9ad109a

Please sign in to comment.