From 5651e890dcef8b0a232fdc9e67576f0ee769c9b4 Mon Sep 17 00:00:00 2001 From: McTom234 <57347686+McTom234@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:21:44 +0200 Subject: [PATCH] fix: `instanceof MedusaError` does not work (#9094) * fix(error): add custom name * revert: remove changeset as requested https://github.com/medusajs/medusa/pull/9094#discussion_r1753971768 * refactor(error): use object identifier to check error type --- packages/core/utils/src/common/errors.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/core/utils/src/common/errors.ts b/packages/core/utils/src/common/errors.ts index 31c50ddb6b..7e1d3744b8 100644 --- a/packages/core/utils/src/common/errors.ts +++ b/packages/core/utils/src/common/errors.ts @@ -29,6 +29,9 @@ export const MedusaErrorCodes = { * @extends Error */ export class MedusaError extends Error { + // Symbol is not serializable + __isMedusaError = true + public type: string public message: string public code?: string @@ -55,4 +58,11 @@ export class MedusaError extends Error { this.message = message this.date = new Date() } + + /** + * Checks the object for the MedusaError type. + */ + static isMedusaError(error: any): error is MedusaError { + return !!error.__isMedusaError + } }