-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(packages/sui-domain): Add DomainError class
- Loading branch information
Alfredo Arronte
committed
Jun 7, 2024
1 parent
b1b8f63
commit f89d4fb
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Base class for handling errors in the domain layer | ||
*/ | ||
export default class DomainError extends Error { | ||
constructor({code, message, cause}) { | ||
super(message, {cause}) | ||
this.name = 'DomainError' | ||
this.code = code | ||
} | ||
|
||
/** | ||
* DomainError factory method | ||
* | ||
* @param {String} code Code to identify the error instance. It's required. | ||
* @param {String} message Description for the error useful for giving more context. | ||
* @param {Object} cause Keeps the original error useful for wrapping uncontrolled errors. | ||
*/ | ||
static create({code, message, cause}) { | ||
if (!code) { | ||
throw new Error('[DomainError] The code property is required.') | ||
} | ||
|
||
return new DomainError({code, message, cause}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters