Skip to content

Commit

Permalink
feat(packages/sui-domain): Add DomainError class
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfredo Arronte committed Jun 7, 2024
1 parent b1b8f63 commit f89d4fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/sui-domain/src/DomainError.js
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})
}
}
1 change: 1 addition & 0 deletions packages/sui-domain/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export {default as DomainError} from './DomainError.js'
export {default as Entity} from './Entity.js'
export {default as EntryPointFactory} from './EntryPointFactory.js'
export {default as FetcherFactory} from './fetcher/factory.js'
Expand Down

0 comments on commit f89d4fb

Please sign in to comment.