|
| 1 | +package errorx |
| 2 | + |
| 3 | +const errUserPrefix = "USER-ERR" |
| 4 | + |
| 5 | +const ( |
| 6 | + needPhone = iota |
| 7 | + needDifferentPhone |
| 8 | + phoneAlreadyExistsInSSO |
| 9 | + forbidChangePhone |
| 10 | + failedToUpdatePhone |
| 11 | + forbidSendPhoneVerifyCodeFrequently |
| 12 | + failedSendPhoneVerifyCode |
| 13 | + phoneVerifyCodeExpiredOrNotFound |
| 14 | + phoneVerifyCodeInvalid |
| 15 | + verificationCodeRequired |
| 16 | + verificationCodeLengthInvalid |
| 17 | + invalidPhoneNumber |
| 18 | + usernameExists |
| 19 | + emailExists |
| 20 | + adminUserCannotBeDeleted |
| 21 | + userHasOrganizations |
| 22 | + userHasDeployments |
| 23 | + userHasBills |
| 24 | +) |
| 25 | + |
| 26 | +var ( |
| 27 | + // phone number is required |
| 28 | + // |
| 29 | + // Description: The request must include a phone number in the header or body to identify the target account. |
| 30 | + // |
| 31 | + // Description_ZH: 请求必须在请求头或正文中包含电话号码以识别目标账户。 |
| 32 | + // |
| 33 | + // en-US: Phone number is required |
| 34 | + // |
| 35 | + // zh-CN: 需要提供电话号码 |
| 36 | + // |
| 37 | + // zh-HK: 需要電話號碼 |
| 38 | + ErrNeedPhone error = CustomError{prefix: errUserPrefix, code: needPhone} |
| 39 | + // new phone number must be different from current phone number |
| 40 | + // |
| 41 | + // Description: The new phone number must be different from the current phone number. |
| 42 | + // |
| 43 | + // Description_ZH: 新电话号码必须与当前电话号码不同。 |
| 44 | + // |
| 45 | + // en-US: New phone number must be different from current phone number |
| 46 | + // |
| 47 | + // zh-CN: 新电话号码必须与当前电话号码不同 |
| 48 | + // |
| 49 | + // zh-HK: 新電話號碼必須與當前電話號碼不同 |
| 50 | + ErrNeedDifferentPhone error = CustomError{prefix: errUserPrefix, code: needDifferentPhone} |
| 51 | + // new phone number already exists in sso service |
| 52 | + // |
| 53 | + // Description: The new phone number already exists in sso service. |
| 54 | + // |
| 55 | + // Description_ZH: 新电话号码已经存在于sso服务中。 |
| 56 | + // |
| 57 | + // en-US: New phone number already exists in sso service |
| 58 | + // |
| 59 | + // zh-CN: 新电话号码已经存在于sso服务中 |
| 60 | + // |
| 61 | + // zh-HK: 新電話號碼已經存在於sso服務中 |
| 62 | + ErrPhoneAlreadyExistsInSSO error = CustomError{prefix: errUserPrefix, code: phoneAlreadyExistsInSSO} |
| 63 | + // forbid change phone number |
| 64 | + // |
| 65 | + // Description: The phone number cannot be changed. |
| 66 | + // |
| 67 | + // Description_ZH: 电话号码不能被更改。 |
| 68 | + // |
| 69 | + // en-US: Forbid change phone number |
| 70 | + // |
| 71 | + // zh-CN: 禁止更改电话号码 |
| 72 | + // |
| 73 | + // zh-HK: 禁止更改電話號碼 |
| 74 | + ErrForbidChangePhone error = CustomError{prefix: errUserPrefix, code: forbidChangePhone} |
| 75 | + // failed to update phone number |
| 76 | + // |
| 77 | + // Description: Failed to update phone number. |
| 78 | + // |
| 79 | + // Description_ZH: 更新电话号码失败。 |
| 80 | + // |
| 81 | + // en-US: Failed to update phone number |
| 82 | + // |
| 83 | + // zh-CN: 更新电话号码失败 |
| 84 | + // |
| 85 | + // zh-HK: 更新電話號碼失敗 |
| 86 | + ErrFailedToUpdatePhone error = CustomError{prefix: errUserPrefix, code: failedToUpdatePhone} |
| 87 | + // forbid send phone verify code frequently |
| 88 | + // |
| 89 | + // Description: Send phone verify code frequently. |
| 90 | + // |
| 91 | + // Description_ZH: 发送手机验证码过于频繁。 |
| 92 | + // |
| 93 | + // en-US: Forbid send phone verify code frequently |
| 94 | + // |
| 95 | + // zh-CN: 禁止频繁发送手机验证码 |
| 96 | + // |
| 97 | + // zh-HK: 禁止頻繁發送手機驗證碼 |
| 98 | + ErrForbidSendPhoneVerifyCodeFrequently error = CustomError{prefix: errUserPrefix, code: forbidSendPhoneVerifyCodeFrequently} |
| 99 | + // failed to send phone verify code |
| 100 | + // |
| 101 | + // Description: Failed to send phone verify code. |
| 102 | + // |
| 103 | + // Description_ZH: 发送手机验证码失败。 |
| 104 | + // |
| 105 | + // en-US: Failed to send phone verify code |
| 106 | + // |
| 107 | + // zh-CN: 发送手机验证码失败 |
| 108 | + // |
| 109 | + // zh-HK: 發送手機驗證碼失敗 |
| 110 | + ErrFailedSendPhoneVerifyCode error = CustomError{prefix: errUserPrefix, code: failedSendPhoneVerifyCode} |
| 111 | + // phone verify code expired or not found |
| 112 | + // |
| 113 | + // Description: Phone verify code expired or not found. |
| 114 | + // |
| 115 | + // Description_ZH: 手机验证码已过期或不存在。 |
| 116 | + // |
| 117 | + // en-US: Phone verify code expired or not found |
| 118 | + // |
| 119 | + // zh-CN: 手机验证码已过期或不存在 |
| 120 | + // |
| 121 | + // zh-HK: 手機驗證碼已過期或不存在 |
| 122 | + ErrPhoneVerifyCodeExpiredOrNotFound error = CustomError{prefix: errUserPrefix, code: phoneVerifyCodeExpiredOrNotFound} |
| 123 | + // phone verify code is invalid |
| 124 | + // |
| 125 | + // Description: Phone verify code is invalid. |
| 126 | + // |
| 127 | + // Description_ZH: 手机验证码无效。 |
| 128 | + // |
| 129 | + // en-US: Phone verify code is invalid |
| 130 | + // |
| 131 | + // zh-CN: 手机验证码无效 |
| 132 | + // |
| 133 | + // zh-HK: 手機驗證碼無效 |
| 134 | + ErrPhoneVerifyCodeInvalid error = CustomError{prefix: errUserPrefix, code: phoneVerifyCodeInvalid} |
| 135 | + |
| 136 | + // verification code can not be empty |
| 137 | + // |
| 138 | + // Description: Verification code can not be empty. |
| 139 | + // |
| 140 | + // Description_ZH: 验证码不能为空。 |
| 141 | + // |
| 142 | + // en-US: Verification code can not be empty |
| 143 | + // |
| 144 | + // zh-CN: 验证码不能为空 |
| 145 | + // |
| 146 | + // zh-HK: 驗證碼不能為空 |
| 147 | + ErrVerificationCodeRequired error = CustomError{prefix: errUserPrefix, code: verificationCodeRequired} |
| 148 | + // verification code length must be 6 |
| 149 | + // |
| 150 | + // Description: Verification code length must be 6. |
| 151 | + // |
| 152 | + // Description_ZH: 验证码长度必须为6。 |
| 153 | + // |
| 154 | + // en-US: Verification code length must be 6 |
| 155 | + // |
| 156 | + // zh-CN: 验证码长度必须为6 |
| 157 | + // |
| 158 | + // zh-HK: 驗證碼長度必須為6 |
| 159 | + ErrVerificationCodeLength error = CustomError{prefix: errUserPrefix, code: verificationCodeLengthInvalid} |
| 160 | + // invalid phone number |
| 161 | + // |
| 162 | + // Description: Invalid phone number. |
| 163 | + // |
| 164 | + // Description_ZH: 无效的电话号码。 |
| 165 | + // |
| 166 | + // en-US: Invalid phone number |
| 167 | + // |
| 168 | + // zh-CN: 无效的电话号码 |
| 169 | + // |
| 170 | + // zh-HK: 無效的電話號碼 |
| 171 | + ErrInvalidPhoneNumber error = CustomError{prefix: errUserPrefix, code: invalidPhoneNumber} |
| 172 | + // username already exists |
| 173 | + // |
| 174 | + // Description: The username provided already exists in the system. |
| 175 | + // |
| 176 | + // Description_ZH: 提供的用户名已存在于系统中。 |
| 177 | + // |
| 178 | + // en-US: Username already exists |
| 179 | + // |
| 180 | + // zh-CN: 用户名已存在 |
| 181 | + // |
| 182 | + // zh-HK: 用戶名已存在 |
| 183 | + ErrUsernameExists error = CustomError{prefix: errUserPrefix, code: usernameExists} |
| 184 | + |
| 185 | + // email already exists in the system |
| 186 | + // |
| 187 | + // Description: The email address provided already exists in the system. |
| 188 | + // |
| 189 | + // Description_ZH: 提供的电子邮件地址已存在于系统中。 |
| 190 | + // |
| 191 | + // en-US: Email already exists |
| 192 | + // |
| 193 | + // zh-CN: 邮箱已存在 |
| 194 | + // |
| 195 | + // zh-HK: 電郵已存在 |
| 196 | + ErrEmailExists error = CustomError{prefix: errUserPrefix, code: emailExists} |
| 197 | + // admin user cannot be deleted |
| 198 | + // |
| 199 | + // Description: The admin user cannot be deleted. |
| 200 | + // |
| 201 | + // Description_ZH: 管理员用户不能被删除。 |
| 202 | + // |
| 203 | + // en-US: Admin user cannot be deleted |
| 204 | + // |
| 205 | + // zh-CN: 管理员用户不能被删除 |
| 206 | + // |
| 207 | + // zh-HK: 管理員用戶不能被刪除 |
| 208 | + ErrAdminUserCannotBeDeleted error = CustomError{prefix: errUserPrefix, code: adminUserCannotBeDeleted} |
| 209 | + // user has organizations can not be deleted |
| 210 | + // |
| 211 | + // Description: The user who owns organizations cannot be deleted. |
| 212 | + // |
| 213 | + // Description_ZH: 拥有组织的用户不能被删除。 |
| 214 | + // |
| 215 | + // en-US: User who owns organizations cannot be deleted |
| 216 | + // |
| 217 | + // zh-CN: 拥有组织的用户不能被删除 |
| 218 | + // |
| 219 | + // zh-HK: 擁有組織的用戶不能被刪除 |
| 220 | + ErrUserHasOrganizations error = CustomError{prefix: errUserPrefix, code: userHasOrganizations} |
| 221 | + // user has deployments can not be deleted |
| 222 | + // |
| 223 | + // Description: The user who owns deployments cannot be deleted. |
| 224 | + // |
| 225 | + // Description_ZH: 拥有部署资源的用户不能被删除。 |
| 226 | + // |
| 227 | + // en-US: User who owns deployments cannot be deleted |
| 228 | + // |
| 229 | + // zh-CN: 拥有部署资源的用户不能被删除 |
| 230 | + // |
| 231 | + // zh-HK: 擁有部署資源的用戶不能被刪除 |
| 232 | + ErrUserHasDeployments error = CustomError{prefix: errUserPrefix, code: userHasDeployments} |
| 233 | + // user has bills can not be deleted |
| 234 | + // |
| 235 | + // Description: The user who owns bills cannot be deleted. |
| 236 | + // |
| 237 | + // Description_ZH: 拥有账单的用户不能被删除。 |
| 238 | + // |
| 239 | + // en-US: User who owns bills cannot be deleted |
| 240 | + // |
| 241 | + // zh-CN: 拥有账单的用户不能被删除 |
| 242 | + // |
| 243 | + // zh-HK: 擁有賬單的用戶不能被刪除 |
| 244 | + ErrUserHasBills error = CustomError{prefix: errUserPrefix, code: userHasBills} |
| 245 | +) |
| 246 | + |
| 247 | +// UsernameExists creates a specific error for username conflicts with the conflicting username |
| 248 | +func UsernameExists(username string) error { |
| 249 | + return CustomError{ |
| 250 | + prefix: errUserPrefix, |
| 251 | + code: usernameExists, |
| 252 | + context: map[string]interface{}{"username": username}, |
| 253 | + } |
| 254 | +} |
| 255 | + |
| 256 | +// EmailExists creates a specific error for email conflicts with the conflicting email |
| 257 | +func EmailExists(email string) error { |
| 258 | + return CustomError{ |
| 259 | + prefix: errUserPrefix, |
| 260 | + code: emailExists, |
| 261 | + context: map[string]interface{}{"email": email}, |
| 262 | + } |
| 263 | +} |
0 commit comments