From 23a5808dde61952e924a2b039cc4ecafd86b39cb Mon Sep 17 00:00:00 2001 From: kurilova Date: Tue, 13 Aug 2024 12:20:13 +0000 Subject: [PATCH] Show error message if provided; show default message if no --- .../interceptors/error.interceptor.spec.ts | 20 ++++++++++++++++++- .../src/app/interceptors/error.interceptor.ts | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/ui/src/app/interceptors/error.interceptor.spec.ts b/modules/ui/src/app/interceptors/error.interceptor.spec.ts index bd8950993..7271223a2 100644 --- a/modules/ui/src/app/interceptors/error.interceptor.spec.ts +++ b/modules/ui/src/app/interceptors/error.interceptor.spec.ts @@ -50,7 +50,7 @@ describe('ErrorInterceptor', () => { expect(interceptor).toBeTruthy(); }); - it('should notify about backend errors', done => { + it('should notify about backend errors with message if exist', done => { const next: HttpHandler = { handle: () => { return throwError( @@ -61,6 +61,24 @@ describe('ErrorInterceptor', () => { const requestMock = new HttpRequest('GET', '/test'); + interceptor.intercept(requestMock, next).subscribe( + () => ({}), + () => { + expect(notificationServiceMock.notify).toHaveBeenCalledWith('error'); + done(); + } + ); + }); + + it('should notify about backend errors with default message', done => { + const next: HttpHandler = { + handle: () => { + return throwError(new HttpErrorResponse({ status: 500 })); + }, + }; + + const requestMock = new HttpRequest('GET', '/test'); + interceptor.intercept(requestMock, next).subscribe( () => ({}), () => { diff --git a/modules/ui/src/app/interceptors/error.interceptor.ts b/modules/ui/src/app/interceptors/error.interceptor.ts index cfa512a85..9e653895a 100644 --- a/modules/ui/src/app/interceptors/error.interceptor.ts +++ b/modules/ui/src/app/interceptors/error.interceptor.ts @@ -66,7 +66,8 @@ export class ErrorInterceptor implements HttpInterceptor { ); } else { this.notificationService.notify( - 'Something went wrong. Check the Terminal for details.' + error.error?.error || + 'Something went wrong. Check the Terminal for details.' ); console.error(error.error?.error || error.message); }