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
This commit is contained in:
@@ -29,6 +29,9 @@ export const MedusaErrorCodes = {
|
|||||||
* @extends Error
|
* @extends Error
|
||||||
*/
|
*/
|
||||||
export class MedusaError extends Error {
|
export class MedusaError extends Error {
|
||||||
|
// Symbol is not serializable
|
||||||
|
__isMedusaError = true
|
||||||
|
|
||||||
public type: string
|
public type: string
|
||||||
public message: string
|
public message: string
|
||||||
public code?: string
|
public code?: string
|
||||||
@@ -55,4 +58,11 @@ export class MedusaError extends Error {
|
|||||||
this.message = message
|
this.message = message
|
||||||
this.date = new Date()
|
this.date = new Date()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the object for the MedusaError type.
|
||||||
|
*/
|
||||||
|
static isMedusaError(error: any): error is MedusaError {
|
||||||
|
return !!error.__isMedusaError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user