瀏覽代碼

CONNECTION_FAILED error as object

Gradually, we exploded the error of CONNECTION_FAILED in multiple
redux state properties. The explosion makes maintenance harder because
the properties have to be updated in sync. Collect them in an object
resembling an Error instance.
j8
Lyubo Marinov 8 年之前
父節點
當前提交
4e0761a46a

+ 3
- 2
connection.js 查看文件

@@ -83,8 +83,9 @@ function connect(id, password, roomName) {
83 83
             ConnectionEvents.CONNECTION_FAILED,
84 84
             connectionFailedHandler);
85 85
 
86
-        function connectionFailedHandler(error, errMsg) {
87
-            APP.store.dispatch(connectionFailed(connection, error, errMsg));
86
+        function connectionFailedHandler(error, message, credentials) {
87
+            APP.store.dispatch(
88
+                connectionFailed(connection, error, message, credentials));
88 89
 
89 90
             if (isFatalJitsiConnectionError(error)) {
90 91
                 connection.removeEventListener(

+ 17
- 2
react/features/authentication/actions.js 查看文件

@@ -127,10 +127,25 @@ export function stopWaitForOwner() {
127 127
  * @private
128 128
  * @returns {{
129 129
  *     type: UPGRADE_ROLE_FINISHED,
130
- *     error: Object
130
+ *     error: ?Object
131 131
  * }}
132 132
  */
133
-function _upgradeRoleFinished(error) {
133
+function _upgradeRoleFinished(error: ?Object) {
134
+    if (error) {
135
+        // Make the specified error object resemble an Error instance (to the
136
+        // extent that jitsi-meet needs it).
137
+        const {
138
+            authenticationError,
139
+            connectionError,
140
+            ...other
141
+        } = error;
142
+
143
+        error = { // eslint-disable-line no-param-reassign
144
+            name: authenticationError || connectionError,
145
+            ...other
146
+        };
147
+    }
148
+
134 149
     return {
135 150
         type: UPGRADE_ROLE_FINISHED,
136 151
         error

+ 31
- 51
react/features/authentication/components/LoginDialog.native.js 查看文件

@@ -64,17 +64,7 @@ class LoginDialog extends Component {
64 64
         /**
65 65
          * The error which occurred during login/authentication.
66 66
          */
67
-        _error: PropTypes.string,
68
-
69
-        /**
70
-         * The credential that the user has failed to authenticate with.
71
-         */
72
-        _errorCredentials: PropTypes.object,
73
-
74
-        /**
75
-         * Any extra details about the error provided by lib-jitsi-meet.
76
-         */
77
-        _errorDetails: PropTypes.string,
67
+        _error: PropTypes.object,
78 68
 
79 69
         /**
80 70
          * Redux store dispatch method.
@@ -118,24 +108,34 @@ class LoginDialog extends Component {
118 108
         const {
119 109
             _connecting: connecting,
120 110
             _error: error,
121
-            _errorCredentials: errorCredentials,
122
-            _errorDetails: errorDetails,
123 111
             t
124 112
         } = this.props;
125 113
 
126
-        let messageKey = '';
127
-        const messageOptions = {};
114
+        let messageKey;
115
+        let messageOptions;
128 116
 
129
-        if (error === JitsiConnectionErrors.PASSWORD_REQUIRED) {
130
-            // Show the message if there's been a user ID or password provided.
131
-            messageKey
132
-                = errorCredentials
133
-                        && (errorCredentials.jid || errorCredentials.password)
134
-                    ? 'dialog.incorrectPassword'
135
-                    : null;
136
-        } else if (error) {
137
-            messageKey = 'dialog.connectErrorWithMsg';
138
-            messageOptions.msg = `${error} ${errorDetails}`;
117
+        if (error) {
118
+            const { name } = error;
119
+
120
+            if (name === JitsiConnectionErrors.PASSWORD_REQUIRED) {
121
+                // Show a message that the credentials are incorrect only if the
122
+                // credentials which have caused the connection to fail are the
123
+                // ones which the user sees.
124
+                const { credentials } = error;
125
+
126
+                if (credentials
127
+                        && credentials.jid
128
+                            === toJid(
129
+                                this.state.username,
130
+                                this.props._configHosts)
131
+                        && credentials.password === this.state.password) {
132
+                    messageKey = 'dialog.incorrectPassword';
133
+                }
134
+            } else if (name) {
135
+                messageKey = 'dialog.connectErrorWithMsg';
136
+                messageOptions || (messageOptions = {});
137
+                messageOptions.msg = `${name} ${error.message}`;
138
+            }
139 139
         }
140 140
 
141 141
         return (
@@ -146,6 +146,8 @@ class LoginDialog extends Component {
146 146
                 titleKey = 'dialog.passwordRequired'>
147 147
                 <View style = { styles.loginDialog }>
148 148
                     <TextInput
149
+                        autoCapitalize = { 'none' }
150
+                        autoCorrect = { false }
149 151
                         onChangeText = { this._onUsernameChange }
150 152
                         placeholder = { 'user@domain.com' }
151 153
                         style = { styles.loginDialogTextInput }
@@ -159,7 +161,7 @@ class LoginDialog extends Component {
159 161
                     <Text style = { styles.loginDialogText }>
160 162
                         {
161 163
                             messageKey
162
-                                ? t(messageKey, messageOptions)
164
+                                ? t(messageKey, messageOptions || {})
163 165
                                 : connecting
164 166
                                     ? t('connection.CONNECTING')
165 167
                                     : ''
@@ -239,9 +241,7 @@ class LoginDialog extends Component {
239 241
  *     _conference: JitsiConference,
240 242
  *     _configHosts: Object,
241 243
  *     _connecting: boolean,
242
- *     _error: string,
243
- *     _errorCredentials: Object,
244
- *     _errorDetails: string
244
+ *     _error: Object
245 245
  * }}
246 246
  */
247 247
 function _mapStateToProps(state) {
@@ -253,34 +253,14 @@ function _mapStateToProps(state) {
253 253
     const { hosts: configHosts } = state['features/base/config'];
254 254
     const {
255 255
         connecting,
256
-        credentials,
257
-        error: connectionError,
258
-        errorMessage: connectionErrorMessage
256
+        error: connectionError
259 257
     } = state['features/base/connection'];
260 258
 
261
-    let error;
262
-    let errorCredentials;
263
-    let errorDetails;
264
-
265
-    if (connectionError) {
266
-        error = connectionError;
267
-        errorCredentials = credentials;
268
-        errorDetails = connectionErrorMessage;
269
-    } else if (upgradeRoleError) {
270
-        error
271
-            = upgradeRoleError.connectionError
272
-                || upgradeRoleError.authenticationError;
273
-        errorCredentials = upgradeRoleError.credentials;
274
-        errorDetails = upgradeRoleError.message;
275
-    }
276
-
277 259
     return {
278 260
         _conference: authRequired,
279 261
         _configHosts: configHosts,
280 262
         _connecting: Boolean(connecting) || Boolean(upgradeRoleInProgress),
281
-        _error: error,
282
-        _errorCredentials: errorCredentials,
283
-        _errorDetails: errorDetails
263
+        _error: connectionError || upgradeRoleError
284 264
     };
285 265
 }
286 266
 

+ 6
- 2
react/features/authentication/middleware.js 查看文件

@@ -95,10 +95,14 @@ MiddlewareRegistry.register(store => next => action => {
95 95
         _hideLoginDialog(store);
96 96
         break;
97 97
 
98
-    case CONNECTION_FAILED:
99
-        action.error === JitsiConnectionErrors.PASSWORD_REQUIRED
98
+    case CONNECTION_FAILED: {
99
+        const { error } = action;
100
+
101
+        error
102
+            && error.name === JitsiConnectionErrors.PASSWORD_REQUIRED
100 103
             && store.dispatch(_openLoginDialog());
101 104
         break;
105
+    }
102 106
 
103 107
     case STOP_WAIT_FOR_OWNER:
104 108
         _clearExistingWaitForOwnerTimeout(store);

+ 1
- 2
react/features/base/connection/actionTypes.js 查看文件

@@ -26,8 +26,7 @@ export const CONNECTION_ESTABLISHED = Symbol('CONNECTION_ESTABLISHED');
26 26
  * {
27 27
  *     type: CONNECTION_FAILED,
28 28
  *     connection: JitsiConnection,
29
- *     error: string,
30
- *     message: string
29
+ *     error: Object | string
31 30
  * }
32 31
  */
33 32
 export const CONNECTION_FAILED = Symbol('CONNECTION_FAILED');

+ 15
- 9
react/features/base/connection/actions.native.js 查看文件

@@ -55,8 +55,8 @@ export function connect(id: ?string, password: ?string) {
55 55
          * disconnected.
56 56
          *
57 57
          * @param {string} message - Disconnect reason.
58
-         * @returns {void}
59 58
          * @private
59
+         * @returns {void}
60 60
          */
61 61
         function _onConnectionDisconnected(message: string) {
62 62
             connection.removeEventListener(
@@ -69,8 +69,8 @@ export function connect(id: ?string, password: ?string) {
69 69
         /**
70 70
          * Resolves external promise when connection is established.
71 71
          *
72
-         * @returns {void}
73 72
          * @private
73
+         * @returns {void}
74 74
          */
75 75
         function _onConnectionEstablished() {
76 76
             unsubscribe();
@@ -86,8 +86,8 @@ export function connect(id: ?string, password: ?string) {
86 86
          * used to authenticate and the authentication failed.
87 87
          * @param {string} [credentials.jid] - The XMPP user's ID.
88 88
          * @param {string} [credentials.password] - The XMPP user's password.
89
-         * @returns {void}
90 89
          * @private
90
+         * @returns {void}
91 91
          */
92 92
         function _onConnectionFailed(err, msg, credentials) {
93 93
             unsubscribe();
@@ -181,9 +181,7 @@ export function connectionEstablished(connection: Object) {
181 181
  * @returns {{
182 182
  *     type: CONNECTION_FAILED,
183 183
  *     connection: JitsiConnection,
184
- *     credentials: Object,
185
- *     error: string,
186
- *     message: string
184
+ *     error: Object
187 185
  * }}
188 186
  */
189 187
 export function connectionFailed(
@@ -194,9 +192,17 @@ export function connectionFailed(
194 192
     return {
195 193
         type: CONNECTION_FAILED,
196 194
         connection,
197
-        credentials,
198
-        error,
199
-        message
195
+
196
+        // Make the error resemble an Error instance (to the extent that
197
+        // jitsi-meet needs it).
198
+        error: {
199
+            credentials:
200
+                credentials && Object.keys(credentials).length
201
+                    ? credentials
202
+                    : undefined,
203
+            message,
204
+            name: error
205
+        }
200 206
     };
201 207
 }
202 208
 

+ 5
- 12
react/features/base/connection/reducer.js 查看文件

@@ -76,8 +76,7 @@ function _connectionEstablished(
76 76
     return assign(state, {
77 77
         connecting: undefined,
78 78
         connection,
79
-        error: undefined,
80
-        errorMessage: undefined
79
+        error: undefined
81 80
     });
82 81
 }
83 82
 
@@ -93,11 +92,9 @@ function _connectionEstablished(
93 92
  */
94 93
 function _connectionFailed(
95 94
         state: Object,
96
-        { connection, credentials, error, message }: {
95
+        { connection, error }: {
97 96
             connection: Object,
98
-            credentials: ?Object,
99
-            error: string,
100
-            message: ?string
97
+            error: Object | string
101 98
         }) {
102 99
     if (state.connection && state.connection !== connection) {
103 100
         return state;
@@ -106,9 +103,7 @@ function _connectionFailed(
106 103
     return assign(state, {
107 104
         connecting: undefined,
108 105
         connection: undefined,
109
-        credentials,
110
-        error,
111
-        errorMessage: message
106
+        error
112 107
     });
113 108
 }
114 109
 
@@ -127,9 +122,7 @@ function _connectionWillConnect(
127 122
         { connection }: { connection: Object }) {
128 123
     return assign(state, {
129 124
         connecting: connection,
130
-        credentials: undefined,
131
-        error: undefined,
132
-        errorMessage: undefined
125
+        error: undefined
133 126
     });
134 127
 }
135 128
 

+ 7
- 3
react/features/base/lib-jitsi-meet/functions.js 查看文件

@@ -39,12 +39,16 @@ export function createLocalTrack(type: string, deviceId: string) {
39 39
  * that category. I've currently named the category fatal because it appears to
40 40
  * be used in the cases of unrecoverable errors that necessitate a reload.
41 41
  *
42
- * @param {string} error - The JitsiConnectionErrors instance to
43
- * categorize/classify.
42
+ * @param {Object|string} error - The JitsiConnectionErrors instance to
43
+ * categorize/classify or an Error-like object.
44 44
  * @returns {boolean} True if the specified JitsiConnectionErrors instance
45 45
  * indicates a fatal JitsiConnection error; otherwise, false.
46 46
  */
47
-export function isFatalJitsiConnectionError(error: string) {
47
+export function isFatalJitsiConnectionError(error: Object | string) {
48
+    if (typeof error !== 'string') {
49
+        error = error.name; // eslint-disable-line no-param-reassign
50
+    }
51
+
48 52
     return (
49 53
         error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
50 54
             || error === JitsiConnectionErrors.OTHER_ERROR

+ 4
- 2
react/features/overlay/reducer.js 查看文件

@@ -89,8 +89,10 @@ function _connectionEstablished(state) {
89 89
  * @returns {Object} The new state of the feature overlay after the reduction of
90 90
  * the specified action.
91 91
  */
92
-function _connectionFailed(state, { error, message }) {
92
+function _connectionFailed(state, { error }) {
93 93
     if (isFatalJitsiConnectionError(error)) {
94
+        const { message } = error;
95
+
94 96
         logger.error(`FATAL XMPP connection error: ${message}`);
95 97
 
96 98
         return assign(state, {
@@ -99,7 +101,7 @@ function _connectionFailed(state, { error, message }) {
99 101
             // From all of the cases above only CONNECTION_DROPPED_ERROR is
100 102
             // considered a network type of failure.
101 103
             isNetworkFailure:
102
-                error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR,
104
+                error.name === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR,
103 105
             reason: `xmpp-conn-dropped: ${message}`
104 106
         });
105 107
     }

Loading…
取消
儲存