mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-4710] Error-proof scan-env (#6724)
* [AAE-4710] Error-proof scan-env * [AAE-4710] Use ts-lint disable
This commit is contained in:
@@ -5,8 +5,8 @@ import { logger } from './logger';
|
||||
interface PeopleTally { enabled: number; disabled: number; }
|
||||
interface RowToPrint { label: string; value: number; }
|
||||
|
||||
const MAX_ATTEMPTS = 10;
|
||||
const TIMEOUT = 60000;
|
||||
const MAX_ATTEMPTS = 1;
|
||||
const TIMEOUT = 180000;
|
||||
const MAX_PEOPLE_PER_PAGE = 100;
|
||||
const USERS_HOME_RELATIVE_PATH = 'User Homes';
|
||||
|
||||
@@ -18,6 +18,9 @@ let loginAttempts: number = 0;
|
||||
|
||||
export default async function main(_args: string[]) {
|
||||
|
||||
// tslint:disable-next-line: no-console
|
||||
console.log = () => {};
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.option('--host <type>', 'Remote environment host')
|
||||
@@ -91,13 +94,18 @@ async function handleLoginError(loginError) {
|
||||
if (loginAttempts === 0) {
|
||||
logger.error(` ${red}Login SSO error${reset}`);
|
||||
}
|
||||
checkEnvReachable(loginError);
|
||||
loginAttempts++;
|
||||
if (MAX_ATTEMPTS === loginAttempts) {
|
||||
if (loginError && loginError.response && loginError.response.text) {
|
||||
const parsedJson = JSON.parse(loginError.response.text);
|
||||
if (typeof parsedJson === 'object' && parsedJson.error) {
|
||||
const { stackTrace, ...errorWithoutDeprecatedProperty } = parsedJson.error;
|
||||
logger.error(errorWithoutDeprecatedProperty);
|
||||
try {
|
||||
const parsedJson = JSON.parse(loginError.response.text);
|
||||
if (typeof parsedJson === 'object' && parsedJson.error) {
|
||||
const { stackTrace, ...errorWithoutDeprecatedProperty } = parsedJson.error;
|
||||
logger.error(errorWithoutDeprecatedProperty);
|
||||
}
|
||||
} catch (jsonParseError) {
|
||||
logger.error(` ${red}Could not parse the error response. Possibly non json format${reset}`);
|
||||
}
|
||||
}
|
||||
logger.error(` ${red}Give up${reset}`);
|
||||
@@ -109,6 +117,14 @@ async function handleLoginError(loginError) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkEnvReachable(loginError) {
|
||||
const failingErrorCodes = ['ENOTFOUND', 'ETIMEDOUT', 'ECONNREFUSED'];
|
||||
if (typeof loginError === 'object' && failingErrorCodes.indexOf(loginError.code) > -1) {
|
||||
logger.error(` ${red}The environment is not reachable (${loginError.code})${reset}`);
|
||||
failScript();
|
||||
}
|
||||
}
|
||||
|
||||
async function getPeopleCount(skipCount: number = 0): Promise<PeopleTally> {
|
||||
if (skipCount === 0) {
|
||||
logger.info(` Fetching number of users`);
|
||||
@@ -193,18 +209,22 @@ async function getFilesCount(): Promise<number> {
|
||||
function handleError(error) {
|
||||
logger.error(` ${red}Error encountered${reset}`);
|
||||
if (error && error.response && error.response.text) {
|
||||
const parsedJson = JSON.parse(error.response.text);
|
||||
if (typeof parsedJson === 'object' && parsedJson.error) {
|
||||
const { stackTrace, ...errorWithoutDeprecatedProperty } = parsedJson.error;
|
||||
logger.error(errorWithoutDeprecatedProperty);
|
||||
try {
|
||||
const parsedJson = JSON.parse(error.response.text);
|
||||
if (typeof parsedJson === 'object' && parsedJson.error) {
|
||||
const { stackTrace, ...errorWithoutDeprecatedProperty } = parsedJson.error;
|
||||
logger.error(errorWithoutDeprecatedProperty);
|
||||
}
|
||||
} catch (jsonParseError) {
|
||||
logger.error(` ${red}Could not parse the error response. Possibly non json format${reset}`);
|
||||
}
|
||||
}
|
||||
failScript();
|
||||
}
|
||||
|
||||
function failScript() {
|
||||
logger.error(`${red}${bright}Environment scan failed. Exiting with non-zero code${reset}`);
|
||||
process.exit(1);
|
||||
logger.error(`${red}${bright}Environment scan failed. Exiting${reset}`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
async function wait(ms: number) {
|
||||
|
Reference in New Issue
Block a user