From 21806b3418a733c795d26fd9b9ea2b6ff4237c34 Mon Sep 17 00:00:00 2001 From: Junyi Date: Tue, 30 Aug 2022 16:03:27 +0800 Subject: [PATCH] fix(plugin-verification): change provider rate limit error to 429 (#788) --- .../plugins/verification/src/actions/verifications.ts | 2 ++ packages/plugins/verification/src/locale/zh-CN.ts | 3 ++- .../plugins/verification/src/providers/sms-aliyun.ts | 10 ++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/plugins/verification/src/actions/verifications.ts b/packages/plugins/verification/src/actions/verifications.ts index 05fbc61c0..563d43ddd 100644 --- a/packages/plugins/verification/src/actions/verifications.ts +++ b/packages/plugins/verification/src/actions/verifications.ts @@ -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 })); diff --git a/packages/plugins/verification/src/locale/zh-CN.ts b/packages/plugins/verification/src/locale/zh-CN.ts index 9d58ccfa6..213a21608 100644 --- a/packages/plugins/verification/src/locale/zh-CN.ts +++ b/packages/plugins/verification/src/locale/zh-CN.ts @@ -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': '您的操作太频繁,请稍后再试' }; diff --git a/packages/plugins/verification/src/providers/sms-aliyun.ts b/packages/plugins/verification/src/providers/sms-aliyun.ts index 3ec2d5efe..f2f0c1fcd 100644 --- a/packages/plugins/verification/src/providers/sms-aliyun.ts +++ b/packages/plugins/verification/src/providers/sms-aliyun.ts @@ -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);