diff --git a/src/app/http-error.interceptor.ts b/src/app/http-error.interceptor.ts index d34db162cba..29333e3f1b5 100644 --- a/src/app/http-error.interceptor.ts +++ b/src/app/http-error.interceptor.ts @@ -9,10 +9,11 @@ import { import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { MatSnackBar } from '@angular/material/snack-bar'; +import { ConfigService } from './services/config.service'; @Injectable() export class HttpErrorInterceptor implements HttpInterceptor { - constructor(public snackBar: MatSnackBar) {} + constructor(protected configService: ConfigService, public snackBar: MatSnackBar) {} intercept(request: HttpRequest, next: HttpHandler): Observable> { return next.handle(request).pipe( @@ -29,11 +30,26 @@ export class HttpErrorInterceptor implements HttpInterceptor { } if (err.status >= 500 || err.status === 0) { - this.snackBar.open($localize`An error occurred. Please refresh this page and try again.`); + this.processError(err); } - return throwError(err); }) ); } + + processError(err: HttpErrorResponse): void { + try { + const requestUrl = new URL(err.url); + if (requestUrl.origin === this.configService.getWISEHostname()) { + this.showError(); + } + } catch (e) { + // request was from a relative (or invalid) URL + this.showError(); + } + } + + showError() { + this.snackBar.open($localize`An error occurred. Please refresh this page and try again.`); + } } diff --git a/src/messages.xlf b/src/messages.xlf index 56f49382c69..95938dfb726 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -4331,21 +4331,21 @@ An error occurred: src/app/http-error.interceptor.ts - 22 + 23 Backend returned code , body was: src/app/http-error.interceptor.ts - 27 + 28 An error occurred. Please refresh this page and try again. src/app/http-error.interceptor.ts - 32 + 53