Skip to content

Commit

Permalink
fix(notifications): Fix notifications url request failure handling (b…
Browse files Browse the repository at this point in the history
…ackport #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 <hdhillon@redhat.com>
  • Loading branch information
mergify[bot] and Hareet Dhillon authored Oct 1, 2021
1 parent 1cd8a97 commit ecbd172
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/app/Shared/Services/NotificationChannel.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
* SOFTWARE.
*/
import { Notifications } from '@app/Notifications/Notifications';
import { BehaviorSubject, combineLatest, from, Observable, Subject } from 'rxjs';
import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
import { fromFetch } from 'rxjs/fetch';
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
import { concatMap, filter, first, map } from 'rxjs/operators';
import { concatMap, filter } from 'rxjs/operators';
import { Base64 } from 'js-base64';
import { ApiService } from './Api.service';

Expand Down Expand Up @@ -74,9 +74,17 @@ export class NotificationChannel {

const notificationsUrl = fromFetch(`${this.apiSvc.authority}/api/v1/notifications_url`)
.pipe(
concatMap(resp => from(resp.json())),
map((url: any): string => url.notificationsUrl)
concatMap(async resp => {
if (resp.ok) {
let body: any = await resp.json();
return body.notificationsUrl;
} else {
let body: string = await resp.text();
throw new Error(resp.status + ' ' + body);
}
})
);

combineLatest(notificationsUrl, this.apiSvc.getToken(), this.apiSvc.getAuthMethod())
.subscribe(
(parts: string[]) => {
Expand Down Expand Up @@ -146,8 +154,8 @@ export class NotificationChannel {
}

private logError(title: string, err: any): void {
window.console.error(err);
this.notifications.danger(title, JSON.stringify(err));
window.console.error(err.stack);
this.notifications.danger(title, JSON.stringify(err.message));
}
}

Expand Down

0 comments on commit ecbd172

Please sign in to comment.