From 6057930ce930617290d0451a44f61bc18fd3eade Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Tue, 5 Jan 2021 01:42:33 +0500 Subject: [PATCH 01/13] Fixed Improvements to error messaging issue #1091 --- src/libs/ErrorMessage/index.js | 21 ++++++++++++++++++ src/libs/ErrorMessage/messages.js | 37 +++++++++++++++++++++++++++++++ src/libs/actions/Session.js | 5 +++-- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/libs/ErrorMessage/index.js create mode 100644 src/libs/ErrorMessage/messages.js diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js new file mode 100644 index 000000000000..db6774f22b26 --- /dev/null +++ b/src/libs/ErrorMessage/index.js @@ -0,0 +1,21 @@ +import _ from 'lodash'; +import messages from './messages'; + +/** + * It's generic function to print any messages. + * + * @param {String} type + * @param {String} error + * @returns {String} + */ +function getErrorMessage(type, error) { + const code = error.split(' ')[0]; + if (!_.isEmpty(code)) { + const message = _.filter(messages, {type: type, errorCode: +code.trim()}); + if (!_.isEmpty(message)) { + return message[0].message; + } + } + return error; +} +export {getErrorMessage}; diff --git a/src/libs/ErrorMessage/messages.js b/src/libs/ErrorMessage/messages.js new file mode 100644 index 000000000000..57436bdd8252 --- /dev/null +++ b/src/libs/ErrorMessage/messages.js @@ -0,0 +1,37 @@ +const messages = [ + { + type: 'Login', + errorCode: 401, + message: 'Incorrect login or password. Please try again.', + }, + { + type: 'Login', + errorCode: 402, + message: + 'You have 2FA enabled on this account. Please sign in using your email or phone number.', + }, + { + type: 'Login', + errorCode: 403, + message: + 'Invalid login or password. Please try again or reset your password.', + }, + { + type: 'Login', + errorCode: 404, + message: + 'We were unable to change your password. This is likely due to an expired password reset link in an old password reset email. We have emailed you a new link so you can try again. Check your Inbox and your Spam folder; it should arrive in just a few minutes.', + }, + { + type: 'Login', + errorCode: 405, + message: + 'You do not have access to this application. Please add your GitHub username for access.', + }, + { + type: 'Login', + errorCode: 413, + message: `Your account has been locked.`, + }, +]; +export default messages; diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index 957e6a23b3ab..e6444b596610 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -8,6 +8,7 @@ import CONFIG from '../../CONFIG'; import PushNotification from '../Notification/PushNotification'; import ROUTES from '../../ROUTES'; import Timing from './Timing'; +import {getErrorMessage} from '../ErrorMessage'; let credentials = {}; Onyx.connect({ @@ -158,14 +159,14 @@ function signIn(password, exitTo, twoFactorAuthCode) { Onyx.merge(ONYXKEYS.CREDENTIALS, {autoGeneratedLogin, autoGeneratedPassword}); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: error.message}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login',error.message)}); }) .finally(() => { Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false}); }); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: error.message, loading: false}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login',error.message), loading: false}); }); } From e97b93cf3f975f12477d8e78e5a9dcafb144cdd5 Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Fri, 8 Jan 2021 07:44:56 +0500 Subject: [PATCH 02/13] Linter fixes, added 2 spaces. --- src/libs/ErrorMessage/index.js | 14 +++---- src/libs/ErrorMessage/messages.js | 70 +++++++++++++++---------------- src/libs/actions/Session.js | 4 +- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index db6774f22b26..e66ce13ad65c 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -9,13 +9,13 @@ import messages from './messages'; * @returns {String} */ function getErrorMessage(type, error) { - const code = error.split(' ')[0]; - if (!_.isEmpty(code)) { - const message = _.filter(messages, {type: type, errorCode: +code.trim()}); - if (!_.isEmpty(message)) { - return message[0].message; + const code = error.split(' ')[0]; + if (!_.isEmpty(code)) { + const message = _.filter(messages, {type: type, errorCode: +code.trim()}); + if (!_.isEmpty(message)) { + return message[0].message; + } } - } - return error; + return error; } export {getErrorMessage}; diff --git a/src/libs/ErrorMessage/messages.js b/src/libs/ErrorMessage/messages.js index 57436bdd8252..35d65b7fbc55 100644 --- a/src/libs/ErrorMessage/messages.js +++ b/src/libs/ErrorMessage/messages.js @@ -1,37 +1,37 @@ const messages = [ - { - type: 'Login', - errorCode: 401, - message: 'Incorrect login or password. Please try again.', - }, - { - type: 'Login', - errorCode: 402, - message: - 'You have 2FA enabled on this account. Please sign in using your email or phone number.', - }, - { - type: 'Login', - errorCode: 403, - message: - 'Invalid login or password. Please try again or reset your password.', - }, - { - type: 'Login', - errorCode: 404, - message: - 'We were unable to change your password. This is likely due to an expired password reset link in an old password reset email. We have emailed you a new link so you can try again. Check your Inbox and your Spam folder; it should arrive in just a few minutes.', - }, - { - type: 'Login', - errorCode: 405, - message: - 'You do not have access to this application. Please add your GitHub username for access.', - }, - { - type: 'Login', - errorCode: 413, - message: `Your account has been locked.`, - }, + { + type: 'Login', + errorCode: 401, + message: 'Incorrect login or password. Please try again.', + }, + { + type: 'Login', + errorCode: 402, + message: + 'You have 2FA enabled on this account. Please sign in using your email or phone number.', + }, + { + type: 'Login', + errorCode: 403, + message: + 'Invalid login or password. Please try again or reset your password.', + }, + { + type: 'Login', + errorCode: 404, + message: + 'We were unable to change your password. This is likely due to an expired password reset link in an old password reset email. We have emailed you a new link so you can try again. Check your Inbox and your Spam folder; it should arrive in just a few minutes.', + }, + { + type: 'Login', + errorCode: 405, + message: + 'You do not have access to this application. Please add your GitHub username for access.', + }, + { + type: 'Login', + errorCode: 413, + message: `Your account has been locked.`, + }, ]; -export default messages; +export default messages; \ No newline at end of file diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index e6444b596610..64514d81d360 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -159,14 +159,14 @@ function signIn(password, exitTo, twoFactorAuthCode) { Onyx.merge(ONYXKEYS.CREDENTIALS, {autoGeneratedLogin, autoGeneratedPassword}); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login',error.message)}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login', error.message)}); }) .finally(() => { Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false}); }); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login',error.message), loading: false}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login', error.message), loading: false}); }); } From 30ad0159e16d850539e3d6f383a53d752d92f1e8 Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Fri, 8 Jan 2021 07:49:38 +0500 Subject: [PATCH 03/13] Fixed a couple of spaces --- src/libs/ErrorMessage/index.js | 10 +++---- src/libs/ErrorMessage/messages.js | 45 ++++++++++++++++--------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index e66ce13ad65c..d95b04b66598 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -11,11 +11,11 @@ import messages from './messages'; function getErrorMessage(type, error) { const code = error.split(' ')[0]; if (!_.isEmpty(code)) { - const message = _.filter(messages, {type: type, errorCode: +code.trim()}); - if (!_.isEmpty(message)) { - return message[0].message; - } + const message = _.filter(messages, {type: type, errorCode: +code.trim()}); + if (!_.isEmpty(message)) { + return message[0].message; + } } return error; } -export {getErrorMessage}; +export {getErrorMessage}; \ No newline at end of file diff --git a/src/libs/ErrorMessage/messages.js b/src/libs/ErrorMessage/messages.js index 35d65b7fbc55..0faf4ee75154 100644 --- a/src/libs/ErrorMessage/messages.js +++ b/src/libs/ErrorMessage/messages.js @@ -1,37 +1,38 @@ const messages = [ { - type: 'Login', - errorCode: 401, - message: 'Incorrect login or password. Please try again.', + type: 'Login', + errorCode: 401, + message: 'Incorrect login or password. Please try again.', }, { - type: 'Login', - errorCode: 402, - message: - 'You have 2FA enabled on this account. Please sign in using your email or phone number.', + type: 'Login', + errorCode: 402, + message: + 'You have 2FA enabled on this account. Please sign in using your email or phone number.', }, { - type: 'Login', - errorCode: 403, - message: - 'Invalid login or password. Please try again or reset your password.', + type: 'Login', + errorCode: 403, + message: + 'Invalid login or password. Please try again or reset your password.', }, { - type: 'Login', - errorCode: 404, - message: - 'We were unable to change your password. This is likely due to an expired password reset link in an old password reset email. We have emailed you a new link so you can try again. Check your Inbox and your Spam folder; it should arrive in just a few minutes.', + type: 'Login', + errorCode: 404, + message: + 'We were unable to change your password. This is likely due to an expired password reset link in an old password reset email. We have emailed you a new link so you can try again. Check your Inbox and your Spam folder; it should arrive in just a few minutes.', }, { - type: 'Login', - errorCode: 405, - message: - 'You do not have access to this application. Please add your GitHub username for access.', + type: 'Login', + errorCode: 405, + message: + 'You do not have access to this application. Please add your GitHub username for access.', }, { - type: 'Login', - errorCode: 413, - message: `Your account has been locked.`, + type: 'Login', + errorCode: 413, + message: 'Your account has been locked.', }, ]; + export default messages; \ No newline at end of file From 687f7587064a1e3b42a31b2e0f5e6186eed4b2d3 Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Fri, 8 Jan 2021 07:53:16 +0500 Subject: [PATCH 04/13] Fixed a few move lines --- src/libs/actions/Session.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index 64514d81d360..4fb1d3acc6b2 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -8,7 +8,7 @@ import CONFIG from '../../CONFIG'; import PushNotification from '../Notification/PushNotification'; import ROUTES from '../../ROUTES'; import Timing from './Timing'; -import {getErrorMessage} from '../ErrorMessage'; +import getErrorMessage from '../ErrorMessage'; let credentials = {}; Onyx.connect({ From f6c220e1a3d2a1abe348689c4f3a9948ede1f618 Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Fri, 8 Jan 2021 07:53:43 +0500 Subject: [PATCH 05/13] Fixed spaces issues. --- src/libs/ErrorMessage/index.js | 2 +- src/libs/ErrorMessage/messages.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index d95b04b66598..d21bb41c79b1 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -18,4 +18,4 @@ function getErrorMessage(type, error) { } return error; } -export {getErrorMessage}; \ No newline at end of file +export default getErrorMessage; diff --git a/src/libs/ErrorMessage/messages.js b/src/libs/ErrorMessage/messages.js index 0faf4ee75154..dfca19edc73d 100644 --- a/src/libs/ErrorMessage/messages.js +++ b/src/libs/ErrorMessage/messages.js @@ -34,5 +34,4 @@ const messages = [ message: 'Your account has been locked.', }, ]; - -export default messages; \ No newline at end of file +export default messages; From 9c4a69e9fc2c5ac770942679d34b5640d314aa6c Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Fri, 8 Jan 2021 07:57:59 +0500 Subject: [PATCH 06/13] property shorthand fixed --- src/libs/ErrorMessage/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index d21bb41c79b1..66a185f1ba12 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -11,9 +11,10 @@ import messages from './messages'; function getErrorMessage(type, error) { const code = error.split(' ')[0]; if (!_.isEmpty(code)) { - const message = _.filter(messages, {type: type, errorCode: +code.trim()}); - if (!_.isEmpty(message)) { - return message[0].message; + const messageObj = _.filter(messages, {type: type, errorCode: +code.trim()}); + if (!_.isEmpty(messageObj)) { + const foundMessage = messageObj[0]; + return foundMessage.message; } } return error; From c03e278b1df6bc7a99c18485c881dd39a5b7c5aa Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Fri, 8 Jan 2021 08:00:23 +0500 Subject: [PATCH 07/13] object-shorthand fixed --- src/libs/ErrorMessage/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index 66a185f1ba12..fcbf0e69ff86 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -11,10 +11,9 @@ import messages from './messages'; function getErrorMessage(type, error) { const code = error.split(' ')[0]; if (!_.isEmpty(code)) { - const messageObj = _.filter(messages, {type: type, errorCode: +code.trim()}); - if (!_.isEmpty(messageObj)) { - const foundMessage = messageObj[0]; - return foundMessage.message; + const message = _.filter(messages, {type, errorCode: +code.trim()}); + if (!_.isEmpty(message)) { + return message[0].message; } } return error; From 3f15c26882a7669924503b920ae5052ddebeddb4 Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Wed, 13 Jan 2021 01:51:36 +0500 Subject: [PATCH 08/13] fixed the error messages --- .../{messages.js => errorMessages.js} | 22 +++++++------------ src/libs/ErrorMessage/index.js | 10 ++++----- src/libs/actions/Session.js | 4 ++-- 3 files changed, 15 insertions(+), 21 deletions(-) rename src/libs/ErrorMessage/{messages.js => errorMessages.js} (67%) diff --git a/src/libs/ErrorMessage/messages.js b/src/libs/ErrorMessage/errorMessages.js similarity index 67% rename from src/libs/ErrorMessage/messages.js rename to src/libs/ErrorMessage/errorMessages.js index dfca19edc73d..dc3cb9964798 100644 --- a/src/libs/ErrorMessage/messages.js +++ b/src/libs/ErrorMessage/errorMessages.js @@ -1,37 +1,31 @@ -const messages = [ +const erroMessages = [ { - type: 'Login', errorCode: 401, - message: 'Incorrect login or password. Please try again.', + errorMessage: 'Incorrect login or password. Please try again.', }, { - type: 'Login', errorCode: 402, - message: + errorMessage: 'You have 2FA enabled on this account. Please sign in using your email or phone number.', }, { - type: 'Login', errorCode: 403, - message: + errorMessage: 'Invalid login or password. Please try again or reset your password.', }, { - type: 'Login', errorCode: 404, - message: + errorMessage: 'We were unable to change your password. This is likely due to an expired password reset link in an old password reset email. We have emailed you a new link so you can try again. Check your Inbox and your Spam folder; it should arrive in just a few minutes.', }, { - type: 'Login', errorCode: 405, - message: + errorMessage: 'You do not have access to this application. Please add your GitHub username for access.', }, { - type: 'Login', errorCode: 413, - message: 'Your account has been locked.', + errorMessage: 'Your account has been locked.', }, ]; -export default messages; +export default erroMessages; diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index fcbf0e69ff86..a37a1a849959 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import messages from './messages'; +import errorMessages from './errorMessages'; /** * It's generic function to print any messages. @@ -8,12 +8,12 @@ import messages from './messages'; * @param {String} error * @returns {String} */ -function getErrorMessage(type, error) { +function getErrorMessage(error) { const code = error.split(' ')[0]; if (!_.isEmpty(code)) { - const message = _.filter(messages, {type, errorCode: +code.trim()}); - if (!_.isEmpty(message)) { - return message[0].message; + const errorMessage = _.filter(errorMessages, {errorCode: +code.trim()}); + if (!_.isEmpty(errorMessage)) { + return errorMessage[0].errorMessage; } } return error; diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index 4fb1d3acc6b2..4aab9e5db53e 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -159,14 +159,14 @@ function signIn(password, exitTo, twoFactorAuthCode) { Onyx.merge(ONYXKEYS.CREDENTIALS, {autoGeneratedLogin, autoGeneratedPassword}); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login', error.message)}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage(error.message)}); }) .finally(() => { Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false}); }); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage('Login', error.message), loading: false}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage(error.message), loading: false}); }); } From 8a0b1149f74fe55cfec0a2e4b54304d1d64b2d67 Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Wed, 13 Jan 2021 01:54:32 +0500 Subject: [PATCH 09/13] removed type --- src/libs/ErrorMessage/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index a37a1a849959..ce4bd9c117ad 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -4,7 +4,6 @@ import errorMessages from './errorMessages'; /** * It's generic function to print any messages. * - * @param {String} type * @param {String} error * @returns {String} */ From d5a16a0b62914c84feab0783379d7ccccecf8e0c Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Wed, 13 Jan 2021 03:14:44 +0500 Subject: [PATCH 10/13] typo fixed and changed the description of function --- src/libs/ErrorMessage/errorMessages.js | 4 ++-- src/libs/ErrorMessage/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ErrorMessage/errorMessages.js b/src/libs/ErrorMessage/errorMessages.js index dc3cb9964798..9ab0facb4b34 100644 --- a/src/libs/ErrorMessage/errorMessages.js +++ b/src/libs/ErrorMessage/errorMessages.js @@ -1,4 +1,4 @@ -const erroMessages = [ +const errorMessages = [ { errorCode: 401, errorMessage: 'Incorrect login or password. Please try again.', @@ -28,4 +28,4 @@ const erroMessages = [ errorMessage: 'Your account has been locked.', }, ]; -export default erroMessages; +export default errorMessages; diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js index ce4bd9c117ad..afdb8311c471 100644 --- a/src/libs/ErrorMessage/index.js +++ b/src/libs/ErrorMessage/index.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import errorMessages from './errorMessages'; /** - * It's generic function to print any messages. + * It's function to print handle error messages in the context of Authenticate. * * @param {String} error * @returns {String} From 0496c93813dfda494eb627427c5054ba15d0781e Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Thu, 14 Jan 2021 08:26:53 +0500 Subject: [PATCH 11/13] Moved & changed the function in Session.js --- ...ages.js => authenticationErrorMessages.js} | 4 ++-- src/libs/ErrorMessage/index.js | 20 ----------------- src/libs/actions/Session.js | 22 ++++++++++++++++--- 3 files changed, 21 insertions(+), 25 deletions(-) rename src/libs/ErrorMessage/{errorMessages.js => authenticationErrorMessages.js} (92%) delete mode 100644 src/libs/ErrorMessage/index.js diff --git a/src/libs/ErrorMessage/errorMessages.js b/src/libs/ErrorMessage/authenticationErrorMessages.js similarity index 92% rename from src/libs/ErrorMessage/errorMessages.js rename to src/libs/ErrorMessage/authenticationErrorMessages.js index 9ab0facb4b34..b8b06b48af06 100644 --- a/src/libs/ErrorMessage/errorMessages.js +++ b/src/libs/ErrorMessage/authenticationErrorMessages.js @@ -1,4 +1,4 @@ -const errorMessages = [ +const authenticationErrorMessages = [ { errorCode: 401, errorMessage: 'Incorrect login or password. Please try again.', @@ -28,4 +28,4 @@ const errorMessages = [ errorMessage: 'Your account has been locked.', }, ]; -export default errorMessages; +export default authenticationErrorMessages; diff --git a/src/libs/ErrorMessage/index.js b/src/libs/ErrorMessage/index.js deleted file mode 100644 index afdb8311c471..000000000000 --- a/src/libs/ErrorMessage/index.js +++ /dev/null @@ -1,20 +0,0 @@ -import _ from 'lodash'; -import errorMessages from './errorMessages'; - -/** - * It's function to print handle error messages in the context of Authenticate. - * - * @param {String} error - * @returns {String} - */ -function getErrorMessage(error) { - const code = error.split(' ')[0]; - if (!_.isEmpty(code)) { - const errorMessage = _.filter(errorMessages, {errorCode: +code.trim()}); - if (!_.isEmpty(errorMessage)) { - return errorMessage[0].errorMessage; - } - } - return error; -} -export default getErrorMessage; diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index 4aab9e5db53e..f7692380ca81 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -8,7 +8,7 @@ import CONFIG from '../../CONFIG'; import PushNotification from '../Notification/PushNotification'; import ROUTES from '../../ROUTES'; import Timing from './Timing'; -import getErrorMessage from '../ErrorMessage'; +import authenticationErrorMessages from '../ErrorMessage/authenticationErrorMessages'; let credentials = {}; Onyx.connect({ @@ -159,14 +159,14 @@ function signIn(password, exitTo, twoFactorAuthCode) { Onyx.merge(ONYXKEYS.CREDENTIALS, {autoGeneratedLogin, autoGeneratedPassword}); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage(error.message)}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getSignInErrorMessage(error.message)}); }) .finally(() => { Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false}); }); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getErrorMessage(error.message), loading: false}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: getSignInErrorMessage(error.message), loading: false}); }); } @@ -242,6 +242,22 @@ function setPassword(password, validateCode) { }); } +/** + * Display a error message in the UI when the API returns an authentication error. + * + * @param {String} error + * @returns {String} + */ +function getSignInErrorMessage(error) { + const code = error.split(' ')[0]; + if (!_.isEmpty(code)) { + const errorMessage = _.filter(authenticationErrorMessages, {errorCode: +code.trim()}); + if (!_.isEmpty(errorMessage)) { + return errorMessage[0].errorMessage; + } + } + return error; +} export { fetchAccountDetails, setGitHubUsername, From 677448f78e3031e324e0b481373ad187c72c03ec Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Thu, 14 Jan 2021 08:36:42 +0500 Subject: [PATCH 12/13] moved the function to API.js --- src/libs/API.js | 18 ++++++++++++++++++ src/libs/actions/Session.js | 21 ++------------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index bb44385aa787..1443562527a8 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -4,6 +4,7 @@ import CONFIG from '../CONFIG'; import ONYXKEYS from '../ONYXKEYS'; import redirectToSignIn from './actions/SignInRedirect'; import * as Network from './Network'; +import authenticationErrorMessages from './ErrorMessage/authenticationErrorMessages'; let isAuthenticating; @@ -480,6 +481,22 @@ function SetPassword(parameters) { requireParameters(['email', 'password', 'validateCode'], parameters, commandName); return request(commandName, parameters); } +/** + * Display a error message in the UI when the API returns an authentication error. + * + * @param {String} error + * @returns {String} + */ +function GetSignInErrorMessage(error) { + const code = error.split(' ')[0]; + if (!_.isEmpty(code)) { + const errorMessage = _.filter(authenticationErrorMessages, {errorCode: +code.trim()}); + if (!_.isEmpty(errorMessage)) { + return errorMessage[0].errorMessage; + } + } + return error; +} export { getAuthToken, @@ -502,4 +519,5 @@ export { SetGithubUsername, SetPassword, User_SignUp, + GetSignInErrorMessage }; diff --git a/src/libs/actions/Session.js b/src/libs/actions/Session.js index f7692380ca81..5123ec3cb715 100644 --- a/src/libs/actions/Session.js +++ b/src/libs/actions/Session.js @@ -8,7 +8,6 @@ import CONFIG from '../../CONFIG'; import PushNotification from '../Notification/PushNotification'; import ROUTES from '../../ROUTES'; import Timing from './Timing'; -import authenticationErrorMessages from '../ErrorMessage/authenticationErrorMessages'; let credentials = {}; Onyx.connect({ @@ -159,14 +158,14 @@ function signIn(password, exitTo, twoFactorAuthCode) { Onyx.merge(ONYXKEYS.CREDENTIALS, {autoGeneratedLogin, autoGeneratedPassword}); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getSignInErrorMessage(error.message)}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: API.GetSignInErrorMessage(error.message)}); }) .finally(() => { Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false}); }); }) .catch((error) => { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: getSignInErrorMessage(error.message), loading: false}); + Onyx.merge(ONYXKEYS.ACCOUNT, {error: API.GetSignInErrorMessage(error.message), loading: false}); }); } @@ -242,22 +241,6 @@ function setPassword(password, validateCode) { }); } -/** - * Display a error message in the UI when the API returns an authentication error. - * - * @param {String} error - * @returns {String} - */ -function getSignInErrorMessage(error) { - const code = error.split(' ')[0]; - if (!_.isEmpty(code)) { - const errorMessage = _.filter(authenticationErrorMessages, {errorCode: +code.trim()}); - if (!_.isEmpty(errorMessage)) { - return errorMessage[0].errorMessage; - } - } - return error; -} export { fetchAccountDetails, setGitHubUsername, From 5212bc6b0a2deb225d7d853ac513d5dd10bc5dba Mon Sep 17 00:00:00 2001 From: Kashan Z Date: Thu, 14 Jan 2021 08:49:49 +0500 Subject: [PATCH 13/13] Linter fixes --- src/libs/API.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/API.js b/src/libs/API.js index 1443562527a8..5728a1afd4bb 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -481,6 +481,7 @@ function SetPassword(parameters) { requireParameters(['email', 'password', 'validateCode'], parameters, commandName); return request(commandName, parameters); } + /** * Display a error message in the UI when the API returns an authentication error. * @@ -519,5 +520,5 @@ export { SetGithubUsername, SetPassword, User_SignUp, - GetSignInErrorMessage + GetSignInErrorMessage, };