Closed bikerp closed 5 years ago
try like this:
function handleCommand(cmd) {
return new Promise((resolve, reject) => {
try {
domain.handle(cmd, err => {
if (err) {
reject(err);
}
resolve();
});
} catch (e) { reject(e); }
});
}
Just a small addition so you won't resolve an already rejected promise:
function handleCommand(cmd) {
return new Promise((resolve, reject) => {
try {
domain.handle(cmd, (err) => {
if (err)
return reject(err);
resolve();
});
} catch (e) { reject(e) }
});
}
note the return statement on the first reject.
right, didn’t see it
Hi @adrai, thanks for the feedback. I tried the try/catch but even this didn't help.
@bikerp This is rather strange, could you post the stack trace of the error?
Error: Please pass a valid aggregate id!
at DefaultCommandHandler.getNextCommandInQueue (C:\Users\bikerp\projects\test\src\commands\node_modules\cqrs-domain\lib\defaultCommandHandler.js:112:17)
at _handle (C:\Users\bikerp\projects\test\src\commands\node_modules\cqrs-domain\lib\defaultCommandHandler.js:1133:27)
at DefaultCommandHandler.handle (C:\Users\bikerp\projects\test\src\commands\node_modules\cqrs-domain\lib\defaultCommandHandler.js:1163:14)
at CommandDispatcher.dispatch (C:\Users\bikerp\projects\test\src\commands\node_modules\cqrs-domain\lib\commandDispatcher.js:119:29)
at C:\Users\bikerp\projects\test\src\commands\node_modules\cqrs-domain\lib\domain.js:670:30
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
Ok, i saw where the problem is. Will submit a fix!
Fixed in v2.14.73.
good catch
@bikerp Could you confirm that solves your issue? So we could close it on our side?
@adrai Good job. It works. Even without the try/catch. Thanks for the quick fix
Hi, I use Promise to handle command:
However the problem is when
Error: Please pass a valid aggregate id!
occurs then the whole process exits and the callback function is not called. Is this a bug or I'm doing it wrong way?Thanks