From df0c1fa0c5b6cfe11e24da6001066ba13f768dc6 Mon Sep 17 00:00:00 2001 From: Nima Date: Thu, 10 Oct 2019 07:11:18 +0330 Subject: [PATCH] Refactor parseErrorCode and try to decrease method complexity (#132) --- app/javascript/src/helper/APIHelper.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/javascript/src/helper/APIHelper.js b/app/javascript/src/helper/APIHelper.js index 9b0e7fac3..a37afb103 100644 --- a/app/javascript/src/helper/APIHelper.js +++ b/app/javascript/src/helper/APIHelper.js @@ -4,12 +4,11 @@ import Auth from '../api/auth'; import router from '../routes'; const parseErrorCode = error => { - if (error.response) { - // 901, 902 are used to identify billing related issues - if ([901, 902].includes(error.response.status)) { - const name = Auth.isAdmin() ? 'billing' : 'billing_deactivated'; - router.push({ name }); - } + const errorStatus = error.response ? error.response.status : undefined; + // 901, 902 are used to identify billing related issues + if ([901, 902].includes(errorStatus)) { + const name = Auth.isAdmin() ? 'billing' : 'billing_deactivated'; + router.push({ name }); } return Promise.reject(error); };