Kaynağa Gözat

[RN] Catch Promise rejection

master
Lyubomir Marinov 9 yıl önce
ebeveyn
işleme
99c2b60a1d
1 değiştirilmiş dosya ile 34 ekleme ve 11 silme
  1. 34
    11
      react/features/app/actions.js

+ 34
- 11
react/features/app/actions.js Dosyayı Görüntüle

@@ -50,18 +50,41 @@ export function appNavigate(urlOrRoom) {
50 50
             // race conditions when we will start to load config multiple times.
51 51
             dispatch(setDomain(domain));
52 52
 
53
-            // If domain has changed, that means we need to load new config
54
-            // for that new domain and set it, and only after that we can
55
-            // navigate to different route.
53
+            // If domain has changed, we need to load the config of the new
54
+            // domain and set it, and only after that we can navigate to
55
+            // different route.
56 56
             loadConfig(`https://${domain}`)
57
-                .then(config => {
58
-                    // We set room name only here to prevent race conditions on
59
-                    // app start to not make app re-render conference page for
60
-                    // two times.
61
-                    dispatch(setRoom(room));
62
-                    dispatch(setConfig(config));
63
-                    _navigate(getState());
64
-                });
57
+                .then(
58
+                    config => configLoaded(/* err */ undefined, config),
59
+                    err => configLoaded(err, /* config */ undefined));
60
+        }
61
+
62
+        /**
63
+         * Notifies that an attempt to load the config(uration) of domain has
64
+         * completed.
65
+         *
66
+         * @param {string|undefined} err - If the loading has failed, the error
67
+         * detailing the cause of the failure.
68
+         * @param {Object|undefined} config - If the loading has succeeded, the
69
+         * loaded config(uration).
70
+         * @returns {void}
71
+         */
72
+        function configLoaded(err, config) {
73
+            if (err) {
74
+                // XXX The failure could be, for example, because of a
75
+                // certificate-related error. In which case the connection will
76
+                // fail later in Strophe anyway even if we use the default
77
+                // config here.
78
+
79
+                // The function loadConfig will log the err.
80
+                return;
81
+            }
82
+
83
+            // We set room name only here to prevent race conditions on app
84
+            // start to not make app re-render conference page for two times.
85
+            dispatch(setRoom(room));
86
+            dispatch(setConfig(config));
87
+            _navigate(getState());
65 88
         }
66 89
     };
67 90
 }

Loading…
İptal
Kaydet