Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle command errors #3

Closed
Matonen opened this issue Nov 3, 2017 · 5 comments
Closed

How to handle command errors #3

Matonen opened this issue Nov 3, 2017 · 5 comments

Comments

@Matonen
Copy link

Matonen commented Nov 3, 2017

How command handlers should implement exception/error handling? Now if execute method throws an error I get node error "UnhandledPromiseRejectionWarning: Unhandled promise rejection".

Should implement catch all exceptions and use resolve function to return something like CommandResult object which have information was command success or not?

@Matonen Matonen changed the title ICommandHandler error/exception handling How to handle command errors Nov 5, 2017
@pawpartyka
Copy link

+1

@kamilmysliwiec
Copy link
Member

Hi,
The only way is to use resolve() method. Something like CommandResult sounds fine. 🙂

@sh3d2
Copy link

sh3d2 commented Feb 7, 2018

Hi,

how about changing ICommandHandler.execute
from

    execute(command: T, resolve: (value?) => void);

to

    execute(command: T): Promise<any>;

that way we'd have full information about whether command handling was successful or not,
and handlers wouldnt have to deal with that ugly-looking-callback-style resolve 😄

@moltar
Copy link

moltar commented Dec 9, 2018

Using CommandResult would not make it possible to retry failed jobs though that are managed by some queue system. E.g. RabbitMQ. If a job failed, it'd go back to the queue and be retried again. This is a very useful pattern. But if all jobs always succeed, then this pattern is not possible.

@mvanderkroon
Copy link

@moltar I am looking exactly for the behaviour you mention: jobs managed by some queue system, such that in case the handler fails either caused by a (transient) exception, or the instance is shutdown, the job is retried automatically. Could you point me towards any resources/examples (anything really) on how to configure NestJS+Sagas in a manner to achieve exactly that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants