From 5d8d2a05c8a54f4af2fa1ba369c7a5d17448ac49 Mon Sep 17 00:00:00 2001 From: seotts Date: Tue, 7 Sep 2021 12:24:02 -0400 Subject: [PATCH] Add transfer error for too many password attempts --- src/views/studio/l10n.json | 1 + src/views/studio/lib/studio-member-actions.js | 4 ++++ .../studio/modals/transfer-host-confirmation.jsx | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/views/studio/l10n.json b/src/views/studio/l10n.json index 9e2eaa04f..646476e4a 100644 --- a/src/views/studio/l10n.json +++ b/src/views/studio/l10n.json @@ -101,6 +101,7 @@ "studio.transfer.forgotPassword": "Forgot password?", "studio.transfer.alert.somethingWentWrong": "Something went wrong transferring this studio to a new host.", "studio.transfer.alert.wasntTheRightPassword": "Hmm, that wasn’t the right password.", + "studio.transfer.alert.tooManyPasswordAttempts": "Too many password attempts. Please try again later.", "studio.transfer.alert.thisUserCannotBecomeHost": "This user cannot become the host — try transfering to another manager", "studio.remove": "Remove", diff --git a/src/views/studio/lib/studio-member-actions.js b/src/views/studio/lib/studio-member-actions.js index b66dbcd1e..69edfd980 100644 --- a/src/views/studio/lib/studio-member-actions.js +++ b/src/views/studio/lib/studio-member-actions.js @@ -11,6 +11,7 @@ const Errors = keyMirror({ SERVER: null, PERMISSION: null, PASSWORD: null, + PASSWORD_ATTEMPT_LIMIT: null, DUPLICATE: null, USER_MUTED: null, UNKNOWN_USERNAME: null, @@ -34,6 +35,9 @@ const normalizeError = (err, body, res) => { if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION; if (res.statusCode === 404) return Errors.UNKNOWN_USERNAME; if (res.statusCode === 409) return Errors.CANNOT_BE_HOST; + if (res.statusCode === 429 && body.message === 'try again later') { + return Errors.PASSWORD_ATTEMPT_LIMIT; + } if (res.statusCode === 429) return Errors.RATE_LIMIT; if (res.statusCode !== 200) return Errors.SERVER; if (body && body.status === 'error') { diff --git a/src/views/studio/modals/transfer-host-confirmation.jsx b/src/views/studio/modals/transfer-host-confirmation.jsx index f74f89c09..a91bc6c71 100644 --- a/src/views/studio/modals/transfer-host-confirmation.jsx +++ b/src/views/studio/modals/transfer-host-confirmation.jsx @@ -51,6 +51,14 @@ const TransferHostConfirmation = ({ } }; + const validationErrorToMessageId = error => { + switch (error) { + case Errors.PASSWORD: return 'studio.transfer.alert.wasntTheRightPassword'; + case Errors.PASSWORD_ATTEMPT_LIMIT: return 'studio.transfer.alert.tooManyPasswordAttempts'; + default: return 'studio.transfer.alert.wasntTheRightPassword'; + } + }; + const handleSubmit = () => { setSubmitting(true); handleTransferHost(passwordInputValue, hostInfo.newHostUsername, selectedId) @@ -64,7 +72,7 @@ const TransferHostConfirmation = ({ }) .catch(e => { // For password errors, show validation alert without closing the modal - if (e === Errors.PASSWORD) { + if (e === Errors.PASSWORD || e === Errors.PASSWORD_ATTEMPT_LIMIT) { setSubmitting(false); setValidationError(e); return; @@ -137,7 +145,9 @@ const TransferHostConfirmation = ({ /> {validationError && }