Sfoglia il codice sorgente

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
master
virtuacoplenny 7 anni fa
parent
commit
1b91e0bc2f

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

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

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

@@ -0,0 +1,28 @@
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 Vedi File

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

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

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

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

@@ -568,7 +568,7 @@ class AddPeopleDialog extends Component<*, *> {
568 568
 
569 569
         let peopleSearchPromise;
570 570
 
571
-        if (this.props.enableAddPeople) {
571
+        if (this.props.enableAddPeople && text) {
572 572
             peopleSearchPromise = searchDirectory(
573 573
                 _peopleSearchUrl,
574 574
                 _jwt,

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

@@ -1,8 +1,44 @@
1 1
 // @flow
2 2
 
3
+import { doGetJSON } from '../base/util';
4
+
3 5
 declare var $: Function;
4 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 43
  * Get the position of the invite option in the interfaceConfig.INVITE_OPTIONS
8 44
  * list.
@@ -78,13 +114,24 @@ export function searchDirectory( // eslint-disable-line max-params
78 114
 ): Promise<Array<Object>> {
79 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 Vedi File

@@ -139,8 +139,9 @@ module.exports = [
139 139
         entry: {
140 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 143
                 'babel-polyfill',
144
+                'whatwg-fetch',
144 145
                 './app.js'
145 146
             ],
146 147
 

Loading…
Annulla
Salva