From 29f51c4dc71f74e7afa3294384fa891a2b5a21ce Mon Sep 17 00:00:00 2001 From: Rob4226 Date: Sat, 5 Aug 2023 04:54:21 -0400 Subject: [PATCH] fix(data): make DataServiceError extend from Error Makes the DataServiceError class inherit from the builtin JavaScript Error. --- modules/data/src/dataservices/data-service-error.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/data/src/dataservices/data-service-error.ts b/modules/data/src/dataservices/data-service-error.ts index 4420f718bc..f6fe794796 100644 --- a/modules/data/src/dataservices/data-service-error.ts +++ b/modules/data/src/dataservices/data-service-error.ts @@ -7,13 +7,12 @@ import { RequestData } from './interfaces'; * @param error the HttpErrorResponse or the error thrown by the service * @param requestData the HTTP request information such as the method and the url. */ -// If extend from Error, `dse instanceof DataServiceError` returns false -// in some (all?) unit tests so don't bother trying. -export class DataServiceError { - message: string | null; - +export class DataServiceError extends Error { constructor(public error: any, public requestData: RequestData | null) { - this.message = typeof error === 'string' ? error : extractMessage(error); + super( + typeof error === 'string' ? error : extractMessage(error) ?? undefined + ); + this.name = this.constructor.name; } }