|
@@ -85,6 +85,12 @@ type State = {
|
85
|
85
|
*/
|
86
|
86
|
broadcasts: ?Array<Object>,
|
87
|
87
|
|
|
88
|
+ /**
|
|
89
|
+ * The error type, as provided by Google, for the most recent error
|
|
90
|
+ * encountered by the Google API.
|
|
91
|
+ */
|
|
92
|
+ errorType: ?string,
|
|
93
|
+
|
88
|
94
|
/**
|
89
|
95
|
* The current state of interactions with the Google API. Determines what
|
90
|
96
|
* Google related UI should display.
|
|
@@ -129,6 +135,7 @@ class StartLiveStreamDialog extends Component<Props, State> {
|
129
|
135
|
|
130
|
136
|
this.state = {
|
131
|
137
|
broadcasts: undefined,
|
|
138
|
+ errorType: undefined,
|
132
|
139
|
googleAPIState: GOOGLE_API_STATES.NEEDS_LOADING,
|
133
|
140
|
googleProfileEmail: '',
|
134
|
141
|
selectedBoundStreamID: undefined,
|
|
@@ -293,6 +300,7 @@ class StartLiveStreamDialog extends Component<Props, State> {
|
293
|
300
|
// Google api. Do not error if the login in canceled.
|
294
|
301
|
if (response && response.result) {
|
295
|
302
|
this._setStateIfMounted({
|
|
303
|
+ errorType: this._parseErrorFromResponse(response),
|
296
|
304
|
googleAPIState: GOOGLE_API_STATES.ERROR
|
297
|
305
|
});
|
298
|
306
|
}
|
|
@@ -427,6 +435,23 @@ class StartLiveStreamDialog extends Component<Props, State> {
|
427
|
435
|
return Object.values(parsedBroadcasts);
|
428
|
436
|
}
|
429
|
437
|
|
|
438
|
+ /**
|
|
439
|
+ * Searches in a Google API error response for the error type.
|
|
440
|
+ *
|
|
441
|
+ * @param {Object} response - The Google API response that may contain an
|
|
442
|
+ * error.
|
|
443
|
+ * @private
|
|
444
|
+ * @returns {string|null}
|
|
445
|
+ */
|
|
446
|
+ _parseErrorFromResponse(response) {
|
|
447
|
+ const result = response.result;
|
|
448
|
+ const error = result.error;
|
|
449
|
+ const errors = error && error.errors;
|
|
450
|
+ const firstError = errors && errors[0];
|
|
451
|
+
|
|
452
|
+ return (firstError && firstError.reason) || null;
|
|
453
|
+ }
|
|
454
|
+
|
430
|
455
|
/**
|
431
|
456
|
* Renders a React Element for authenticating with the Google web client.
|
432
|
457
|
*
|
|
@@ -485,7 +510,7 @@ class StartLiveStreamDialog extends Component<Props, State> {
|
485
|
510
|
onClick = { this._onRequestGoogleSignIn }
|
486
|
511
|
text = { t('liveStreaming.signIn') } />
|
487
|
512
|
);
|
488
|
|
- helpText = t('liveStreaming.errorAPI');
|
|
513
|
+ helpText = this._getGoogleErrorMessageToDisplay();
|
489
|
514
|
|
490
|
515
|
break;
|
491
|
516
|
|
|
@@ -512,6 +537,23 @@ class StartLiveStreamDialog extends Component<Props, State> {
|
512
|
537
|
);
|
513
|
538
|
}
|
514
|
539
|
|
|
540
|
+ /**
|
|
541
|
+ * Returns the error message to display for the current error state.
|
|
542
|
+ *
|
|
543
|
+ * @private
|
|
544
|
+ * @returns {string} The error message to display.
|
|
545
|
+ */
|
|
546
|
+ _getGoogleErrorMessageToDisplay() {
|
|
547
|
+ switch (this.state.errorType) {
|
|
548
|
+ case 'liveStreamingNotEnabled':
|
|
549
|
+ return this.props.t(
|
|
550
|
+ 'liveStreaming.errorLiveStreamNotEnabled',
|
|
551
|
+ { email: this.state.googleProfileEmail });
|
|
552
|
+ default:
|
|
553
|
+ return this.props.t('liveStreaming.errorAPI');
|
|
554
|
+ }
|
|
555
|
+ }
|
|
556
|
+
|
515
|
557
|
/**
|
516
|
558
|
* Updates the internal state if the component is still mounted. This is a
|
517
|
559
|
* workaround for all the state setting that occurs after ajax.
|