Browse Source

improve invite error handling (#2649)

* fix(invite): do not send empty queries for people search

The endpoint might return an error if an empty query is sent.

* fix(invite): add error logging for failed people directory requests

The error currently being passed through from $.getJSON ended up
being an empty string plus was not getting logged. So switch to
fetch to move along with jquery killing and log the error.

* fix(dial-in): add error logging for failed requests

* ref(invite): create a fetch helper to remove duplicate logic
j8
virtuacoplenny 7 years ago
parent
commit
1b91e0bc2f

+ 5
- 1
react/features/base/react/components/web/MultiSelectAutocomplete.js View File

6
 
6
 
7
 import InlineDialogFailure from './InlineDialogFailure';
7
 import InlineDialogFailure from './InlineDialogFailure';
8
 
8
 
9
+const logger = require('jitsi-meet-logger').getLogger(__filename);
10
+
9
 /**
11
 /**
10
  * A MultiSelect that is also auto-completing.
12
  * A MultiSelect that is also auto-completing.
11
  */
13
  */
290
                     error: false
292
                     error: false
291
                 });
293
                 });
292
             })
294
             })
293
-            .catch(() => {
295
+            .catch(error => {
296
+                logger.error('MultiSelectAutocomplete error in query', error);
297
+
294
                 this.setState({
298
                 this.setState({
295
                     error: true,
299
                     error: true,
296
                     loading: false,
300
                     loading: false,

+ 28
- 0
react/features/base/util/httpUtils.js View File

1
+const logger = require('jitsi-meet-logger').getLogger(__filename);
2
+
3
+/**
4
+ * Wrapper around fetch GET requests to handle json-ifying the response
5
+ * and logging errors.
6
+ *
7
+ * @param {string} url - The URL to perform a GET against.
8
+ * @returns {Promise<Object>} The response body, in JSON format, will be
9
+ * through the Promise.
10
+ */
11
+export function doGetJSON(url) {
12
+    return fetch(url)
13
+        .then(response => {
14
+            const jsonify = response.json();
15
+
16
+            if (response.ok) {
17
+                return jsonify;
18
+            }
19
+
20
+            return jsonify
21
+                .then(result => Promise.reject(result));
22
+        })
23
+        .catch(error => {
24
+            logger.error('Error performing get:', url, error);
25
+
26
+            return Promise.reject(error);
27
+        });
28
+}

+ 1
- 0
react/features/base/util/index.js View File

1
 export * from './helpers';
1
 export * from './helpers';
2
+export * from './httpUtils';
2
 export * from './loadScript';
3
 export * from './loadScript';
3
 export * from './randomUtil';
4
 export * from './randomUtil';
4
 export * from './uri';
5
 export * from './uri';

+ 3
- 6
react/features/invite/actions.js View File

5
     UPDATE_DIAL_IN_NUMBERS_FAILED,
5
     UPDATE_DIAL_IN_NUMBERS_FAILED,
6
     UPDATE_DIAL_IN_NUMBERS_SUCCESS
6
     UPDATE_DIAL_IN_NUMBERS_SUCCESS
7
 } from './actionTypes';
7
 } from './actionTypes';
8
-
9
-declare var $: Function;
8
+import { getDialInConferenceID, getDialInNumbers } from './functions';
10
 
9
 
11
 /**
10
 /**
12
  * Opens the inline conference info dialog.
11
  * Opens the inline conference info dialog.
48
         }
47
         }
49
 
48
 
50
         const { room } = state['features/base/conference'];
49
         const { room } = state['features/base/conference'];
51
-        const conferenceIDURL
52
-            = `${dialInConfCodeUrl}?conference=${room}@${mucURL}`;
53
 
50
 
54
         Promise.all([
51
         Promise.all([
55
-            $.getJSON(dialInNumbersUrl),
56
-            $.getJSON(conferenceIDURL)
52
+            getDialInNumbers(dialInNumbersUrl),
53
+            getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
57
         ])
54
         ])
58
             .then(([ dialInNumbers, { conference, id, message } ]) => {
55
             .then(([ dialInNumbers, { conference, id, message } ]) => {
59
                 if (!conference || !id) {
56
                 if (!conference || !id) {

+ 1
- 1
react/features/invite/components/AddPeopleDialog.web.js View File

568
 
568
 
569
         let peopleSearchPromise;
569
         let peopleSearchPromise;
570
 
570
 
571
-        if (this.props.enableAddPeople) {
571
+        if (this.props.enableAddPeople && text) {
572
             peopleSearchPromise = searchDirectory(
572
             peopleSearchPromise = searchDirectory(
573
                 _peopleSearchUrl,
573
                 _peopleSearchUrl,
574
                 _jwt,
574
                 _jwt,

+ 54
- 7
react/features/invite/functions.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
+import { doGetJSON } from '../base/util';
4
+
3
 declare var $: Function;
5
 declare var $: Function;
4
 declare var interfaceConfig: Object;
6
 declare var interfaceConfig: Object;
5
 
7
 
8
+const logger = require('jitsi-meet-logger').getLogger(__filename);
9
+
10
+/**
11
+ * Sends a GET request to obtain the conference ID necessary for identifying
12
+ * which conference to join after diaing the dial-in service.
13
+ *
14
+ * @param {string} baseUrl - The url for obtaining the conference ID (pin) for
15
+ * dialing into a conference.
16
+ * @param {string} roomName - The conference name to find the associated
17
+ * conference ID.
18
+ * @param {string} mucURL - In which MUC the conference exists.
19
+ * @returns {Promise} - The promise created by the request.
20
+ */
21
+export function getDialInConferenceID(
22
+        baseUrl: string,
23
+        roomName: string,
24
+        mucURL: string): Promise<Object> {
25
+    const conferenceIDURL = `${baseUrl}?conference=${roomName}@${mucURL}`;
26
+
27
+    return doGetJSON(conferenceIDURL);
28
+}
29
+
30
+/**
31
+ * Sends a GET request for phone numbers used to dial into a conference.
32
+ *
33
+ * @param {string} url - The service that returns confernce dial-in numbers.
34
+ * @returns {Promise} - The promise created by the request. The returned numbers
35
+ * may be an array of numbers or an object with countries as keys and arrays of
36
+ * phone number strings.
37
+ */
38
+export function getDialInNumbers(url: string): Promise<*> {
39
+    return doGetJSON(url);
40
+}
41
+
6
 /**
42
 /**
7
  * Get the position of the invite option in the interfaceConfig.INVITE_OPTIONS
43
  * Get the position of the invite option in the interfaceConfig.INVITE_OPTIONS
8
  * list.
44
  * list.
78
 ): Promise<Array<Object>> {
114
 ): Promise<Array<Object>> {
79
     const queryTypesString = JSON.stringify(queryTypes);
115
     const queryTypesString = JSON.stringify(queryTypes);
80
 
116
 
81
-    return new Promise((resolve, reject) => {
82
-        $.getJSON(
83
-                `${serviceUrl}?query=${encodeURIComponent(text)}&queryTypes=${
84
-                    queryTypesString}&jwt=${jwt}`,
85
-                resolve)
86
-            .catch((jqxhr, textStatus, error) => reject(error));
87
-    });
117
+    return fetch(`${serviceUrl}?query=${encodeURIComponent(text)}&queryTypes=${
118
+        queryTypesString}&jwt=${jwt}`)
119
+            .then(response => {
120
+                const jsonify = response.json();
121
+
122
+                if (response.ok) {
123
+                    return jsonify;
124
+                }
125
+
126
+                return jsonify
127
+                    .then(result => Promise.reject(result));
128
+            })
129
+            .catch(error => {
130
+                logger.error(
131
+                    'Error searching directory:', error);
132
+
133
+                return Promise.reject(error);
134
+            });
88
 }
135
 }
89
 
136
 
90
 /**
137
 /**

+ 2
- 1
webpack.config.js View File

139
         entry: {
139
         entry: {
140
             'app.bundle': [
140
             'app.bundle': [
141
 
141
 
142
-                // XXX Required by at least IE11 at the time of this writing.
142
+                // babel-polyfill and fetch polyfill are required for IE11.
143
                 'babel-polyfill',
143
                 'babel-polyfill',
144
+                'whatwg-fetch',
144
                 './app.js'
145
                 './app.js'
145
             ],
146
             ],
146
 
147
 

Loading…
Cancel
Save