From 8b5a6ac778968162a35ad351d843f23e0462664b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 22 Jun 2023 16:28:18 +0200 Subject: [PATCH] try to work better with minified code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- packages/errors/src/errors/CustomErrorBase.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/errors/src/errors/CustomErrorBase.ts b/packages/errors/src/errors/CustomErrorBase.ts index af3c10956f..ea9c91f173 100644 --- a/packages/errors/src/errors/CustomErrorBase.ts +++ b/packages/errors/src/errors/CustomErrorBase.ts @@ -22,8 +22,11 @@ import { isError } from './assertion'; * * @public * @example - *```ts - * class MyCustomError extends CustomErrorBase {} + * + * ```ts + * class MyCustomError extends CustomErrorBase { + * name = 'MyCustomError' as const; + * } * * const e = new MyCustomError('Some message', cause); * // e.name === 'MyCustomError' @@ -53,8 +56,11 @@ export class CustomErrorBase extends Error { Error.captureStackTrace?.(this, this.constructor); - if (!this.name) { - this.name = this.constructor.name; + if (!this.name || this.name === 'Error') { + const baseName = this.constructor.name; + if (baseName !== 'Error') { + this.name = this.constructor.name; + } } this.cause = isError(cause) ? cause : undefined;