Comments (5)
The type (prototype) of the events are note exposed. Why do you need it? Can't you simple check err.name
or
subscribe to domain.onEvent(function (evt) {}); ?
from node-cqrs-domain.
Type of the events or type of the errors? It's the latter (the error types) I was talking about.
In my case, I had to implement custom command handler to perform cross-aggregate validation (check that the aggregate referenced by parentId property of the command already exists.) If that validation failed, I would call the callback with ValidationError and that would eventually cause domain.createCommandRejectedEvent() to create a CommandRejected event. The problem is that neither ValidationError nor any other pre-defined error type that createCommandRejectedEvent method checks against are exposed (?). Any other error type causes createCommandRejectedEvent to do nothing.
https://github.com/adrai/node-cqrs-domain/blob/master/lib/domain.js#L173
The code:
module.exports = require('cqrs-domain').defineCommandHandler({
}, function (aggregateId, command, commandHandler, callback) {
// if 'command.parentEntryId' is provided, check that the parent entity exists
// everything else - just follow DefaultCommandHandler
var self = this;
var parentId = !!this.definitions.command.payload && !!command.payload.parentEntityId
? command.payload.parentEntityId
: null; // use 'dotty'
async.waterfall([
function (clb) {
if (!!parentId) {
self.loadAggregate(command.payload.parentEntityId, clb);
} else {
clb(null, null, null, false);
}
},
function (aggregate, stream, isNewSnapShotNeeded, clb) {
if (!!parentId && (!aggregate || aggregate.getRevision() === 0)) {
clb(// new ValidationError('Parent Entity with id: ' + parentId + ' does not exist')
{ name: 'ValidationError', message: 'Parent Entity with id: ' + parentId + ' does not exist' }
);
} else {
clb(null);
}
}
],
function (err) {
if (!!err) {
callback(err);
} else {
self.workflow(aggregateId, command, callback);
}
}
)
});
from node-cqrs-domain.
Ok I see what you mean... I will expose these errors for the next release, ok?
from node-cqrs-domain.
Thank you!
from node-cqrs-domain.
v1.4.1
from node-cqrs-domain.
Related Issues (20)
- Let MongoDB generate the aggregate ID? HOT 6
- Is it possible to replace the t4-validation? HOT 5
- CQRS Question about bulk import HOT 5
- revision guard HOT 6
- [Bug] Precondition aggregate is empty HOT 2
- How to use in AWS Lambda HOT 5
- Can a command fire more than one event? HOT 3
- Access meta in command HOT 2
- How to use domainPath in unit tests HOT 7
- Context and aggregateId HOT 5
- defaultCommandHandler bug, adding "undefined" to array of evtsToDispatch HOT 1
- How to clear/init HOT 2
- Same event name in different contexts HOT 2
- default value command schema HOT 2
- Where to catch Error: Please pass a valid aggregate id! HOT 11
- Transaction with two aggregates HOT 1
- How to handle errors thrown from defineCommand / defineEvent handlers? HOT 9
- Unique field validation HOT 7
- rollback aggregate to a given revision HOT 5
- Update deps HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-cqrs-domain.