1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const CONFIG_ERROR_CODE = 105;
|
4 | const BROWSER_CONNECT_ERROR_CODE = 135;
|
5 | const KITCHEN_SINK_CODE = 199;
|
6 | class IError extends Error {
|
7 | }
|
8 | exports.IError = IError;
|
9 | class ProtractorError extends IError {
|
10 | constructor(logger, message, code, error) {
|
11 | super(message);
|
12 | this.message = message;
|
13 | this.code = code;
|
14 |
|
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 | }
|
34 | ProtractorError.CODE = KITCHEN_SINK_CODE;
|
35 | ProtractorError.SUPRESS_EXIT_CODE = false;
|
36 | exports.ProtractorError = ProtractorError;
|
37 |
|
38 |
|
39 |
|
40 | class ConfigError extends ProtractorError {
|
41 | constructor(logger, message, error) {
|
42 | super(logger, message, ConfigError.CODE, error);
|
43 | }
|
44 | }
|
45 | ConfigError.CODE = CONFIG_ERROR_CODE;
|
46 | exports.ConfigError = ConfigError;
|
47 |
|
48 |
|
49 |
|
50 | class BrowserError extends ProtractorError {
|
51 | constructor(logger, message) {
|
52 | super(logger, message, BrowserError.CODE);
|
53 | }
|
54 | }
|
55 | BrowserError.CODE = BROWSER_CONNECT_ERROR_CODE;
|
56 | BrowserError.ERR_MSGS = [
|
57 | 'ECONNREFUSED connect ECONNREFUSED', 'Sauce Labs Authentication Error',
|
58 | 'Invalid username or password'
|
59 | ];
|
60 | exports.BrowserError = BrowserError;
|
61 | class 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 | }
|
83 | exports.ErrorHandler = ErrorHandler;
|
84 |
|
\ | No newline at end of file |