Skip to content

Commit ecbd172

Browse files
mergify[bot]Hareet Dhillon
andauthored
fix(notifications): Fix notifications url request failure handling (backport #310) (#311)
* fix(notifications): Fix notifications url request failure handling (#310) * Replace concatMap using in response JSON parsing with a switchMap * Revert back to concatMap and throw an error containing the response status code and text * Clean-up syntax * fixup! Clean-up syntax * Log err.message instead of just the err object * Fix code changed during rebase * Include response body for more detailed error info * Clean up imports * Make error logging more specific (cherry picked from commit 9e86184) # Conflicts: # src/app/Shared/Services/NotificationChannel.service.tsx * fix(notifications): Fix notifications url request failure handling (#310) * Replace concatMap using in response JSON parsing with a switchMap * Revert back to concatMap and throw an error containing the response status code and text * Clean-up syntax * fixup! Clean-up syntax * Log err.message instead of just the err object * Fix code changed during rebase * Include response body for more detailed error info * Clean up imports * Make error logging more specific * Remove unused imports Co-authored-by: Hareet Dhillon <[email protected]>
1 parent 1cd8a97 commit ecbd172

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/app/Shared/Services/NotificationChannel.service.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
* SOFTWARE.
3737
*/
3838
import { Notifications } from '@app/Notifications/Notifications';
39-
import { BehaviorSubject, combineLatest, from, Observable, Subject } from 'rxjs';
39+
import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
4040
import { fromFetch } from 'rxjs/fetch';
4141
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
42-
import { concatMap, filter, first, map } from 'rxjs/operators';
42+
import { concatMap, filter } from 'rxjs/operators';
4343
import { Base64 } from 'js-base64';
4444
import { ApiService } from './Api.service';
4545

@@ -74,9 +74,17 @@ export class NotificationChannel {
7474

7575
const notificationsUrl = fromFetch(`${this.apiSvc.authority}/api/v1/notifications_url`)
7676
.pipe(
77-
concatMap(resp => from(resp.json())),
78-
map((url: any): string => url.notificationsUrl)
77+
concatMap(async resp => {
78+
if (resp.ok) {
79+
let body: any = await resp.json();
80+
return body.notificationsUrl;
81+
} else {
82+
let body: string = await resp.text();
83+
throw new Error(resp.status + ' ' + body);
84+
}
85+
})
7986
);
87+
8088
combineLatest(notificationsUrl, this.apiSvc.getToken(), this.apiSvc.getAuthMethod())
8189
.subscribe(
8290
(parts: string[]) => {
@@ -146,8 +154,8 @@ export class NotificationChannel {
146154
}
147155

148156
private logError(title: string, err: any): void {
149-
window.console.error(err);
150-
this.notifications.danger(title, JSON.stringify(err));
157+
window.console.error(err.stack);
158+
this.notifications.danger(title, JSON.stringify(err.message));
151159
}
152160
}
153161

0 commit comments

Comments
 (0)