exitCodes.js 2.56 KB
Newer Older
Kriengkrai Yothee's avatar
Kriengkrai Yothee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const CONFIG_ERROR_CODE = 105;
const BROWSER_CONNECT_ERROR_CODE = 135;
const KITCHEN_SINK_CODE = 199;
class IError extends Error {
}
exports.IError = IError;
class ProtractorError extends IError {
    constructor(logger, message, code, error) {
        super(message);
        this.message = message;
        this.code = code;
        // replacing the stack trace with the thrown error stack trace.
        if (error) {
            let protractorError = error;
            this.stack = protractorError.stack;
        }
        ProtractorError.log(logger, this.code, this.message, this.stack);
        if (!ProtractorError.SUPRESS_EXIT_CODE) {
            process.exit(this.code);
        }
    }
    static log(logger, code, message, stack) {
        let messages = message.split('\n');
        if (messages.length > 1) {
            message = messages[0];
        }
        logger.error('Error code: ' + code);
        logger.error('Error message: ' + message);
        logger.error(stack);
    }
}
ProtractorError.CODE = KITCHEN_SINK_CODE;
ProtractorError.SUPRESS_EXIT_CODE = false;
exports.ProtractorError = ProtractorError;
/**
 * Configuration file error
 */
class ConfigError extends ProtractorError {
    constructor(logger, message, error) {
        super(logger, message, ConfigError.CODE, error);
    }
}
ConfigError.CODE = CONFIG_ERROR_CODE;
exports.ConfigError = ConfigError;
/**
 * Browser errors including getting a driver session, direct connect, etc.
 */
class BrowserError extends ProtractorError {
    constructor(logger, message) {
        super(logger, message, BrowserError.CODE);
    }
}
BrowserError.CODE = BROWSER_CONNECT_ERROR_CODE;
BrowserError.ERR_MSGS = [
    'ECONNREFUSED connect ECONNREFUSED', 'Sauce Labs Authentication Error',
    'Invalid username or password'
];
exports.BrowserError = BrowserError;
class ErrorHandler {
    static isError(errMsgs, e) {
        if (errMsgs && errMsgs.length > 0) {
            for (let errPos in errMsgs) {
                let errMsg = errMsgs[errPos];
                if (e.message && e.message.indexOf(errMsg) !== -1) {
                    return true;
                }
            }
        }
        return false;
    }
    static parseError(e) {
        if (ErrorHandler.isError(ConfigError.ERR_MSGS, e)) {
            return ConfigError.CODE;
        }
        if (ErrorHandler.isError(BrowserError.ERR_MSGS, e)) {
            return BrowserError.CODE;
        }
        return null;
    }
}
exports.ErrorHandler = ErrorHandler;
//# sourceMappingURL=exitCodes.js.map