How to handle errors thrown from defineCommand / defineEvent handlers?
See original GitHub issueHi! For example:
export = domain.defineEvent({}, (data, aggregate) => {
aggregate.set('balance', data.balance);
aggregate.set('value', data.value);
throw new FakeError(); // unhandled, something went wrong or TypeError
});
how to handle such type of errors?
Approach listed below doesn’t help.
async handle(data: object) {
return new Promise((resolve, reject) => {
try {
this.domain.handle(data, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
} catch (e) {
reject(e);
}
});
}
This problem is similar for defineViewBuilder of eventdenormalizer. Can’t catch errors there too.
another a little question: Why custom command handler is so bad?
Command Handler (Be careful!!!)
Is your use case not solvable without a custom command handling? Sagas? Micro-Services?
what if I need to make external operation like 3rd party API http call and generate event with resulted data without saving to eventstore. This event then can be handled by sagas to generate command to update required aggregate.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How to catch an exception inside an event listener?
on handler is located inside a try..catch block, the function is executed asynchronously and therefore any error thrown inside this function is ...
Read more >Exceptions thrown from within event handlers crashes the app
Current behavior. Exception thrown from within EventHandlers craches the app. Expected behavior. A way to handle and don't crash the app.
Read more >Window: error event - Web APIs - MDN Web Docs - Mozilla
The error being thrown. Usually an Error object. Note: These parameter names are observable with an HTML event handler attribute, where the ...
Read more >Error Handling — The Swift Programming Language (Swift 5.7)
When a function throws an error, it changes the flow of your program, so it's important that you can quickly identify places in...
Read more >Handle errors in ASP.NET Core | Microsoft Learn
If the alternate pipeline throws an exception of its own, Exception Handling Middleware rethrows the original exception.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
currently we are at stage of investigating and collecting potential issues before the real start of development. As soon as we will do it wait PR from us 😃
Always happy for a PR.