fix(plugin-verification): change provider rate limit error to 429 (#788)

This commit is contained in:
Junyi 2022-08-30 16:03:27 +08:00 committed by GitHub
parent d1b52c7d96
commit 21806b3418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -69,6 +69,8 @@ export async function create(context: Context, next: Next) {
case 'InvalidReceiver':
// TODO: message should consider email and other providers, maybe use "receiver"
return context.throw(400, context.t('Not a valid cellphone number, please re-enter', {ns: namespace }));
case 'RateLimit':
return context.throw(429, context.t('You are trying so frequently, please slow down', { ns: namespace }));
default:
console.error(error);
return context.throw(500, context.t('Verification send failed, please try later or contact to administrator', { ns: namespace }));

View File

@ -1,5 +1,6 @@
export default {
'Verification send failed, please try later or contact to administrator': '验证码发送失败,请稍后重试或联系管理员',
'Not a valid cellphone number, please re-enter': '不是有效的手机号,请重新输入',
"Please don't retry in {{time}} seconds": '请 {{time}} 秒后再试'
"Please don't retry in {{time}} seconds": '请 {{time}} 秒后再试',
'You are trying so frequently, please slow down': '您的操作太频繁,请稍后再试'
};

View File

@ -33,11 +33,9 @@ export default class extends Provider {
templateParam: JSON.stringify(data)
});
const { i18n } = this.plugin.app;
try {
const { body } = await this.client.sendSmsWithOptions(request, new RuntimeOptions({}));
let err = new Error();
let err = new Error(body.message);
switch (body.code) {
case 'OK':
break;
@ -47,8 +45,12 @@ export default class extends Provider {
return Promise.reject(err);
case 'isv.BUSINESS_LIMIT_CONTROL':
// should not let user to know
err.name = 'RateLimit';
console.error(body);
return Promise.reject(err);
default:
// should not let user to know
console.error(body);
err.name = 'SendSMSFailed';
return Promise.reject(err);