UNPKG

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