Skip to content

Commit

Permalink
fix: instanceof MedusaError does not work (#9107)
Browse files Browse the repository at this point in the history
The same as #9094, but for v1. Our project won't be moving to v2 soon probably, and we want the feature of course 😄 

Co-authored-by: Riqwan Thamir <[email protected]>
  • Loading branch information
McTom234 and riqwan authored Sep 12, 2024
1 parent e030fe2 commit 7488562
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-oranges-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

feat(utils): adds an identifier for MedusaError
9 changes: 9 additions & 0 deletions packages/utils/src/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const MedusaErrorCodes = {
* @extends Error
*/
export class MedusaError extends Error {
__isMedusaError = true

public type: string
public message: string
public code?: string
Expand All @@ -52,4 +54,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
}
}

0 comments on commit 7488562

Please sign in to comment.