[Meteor 3.0] Promise rejection stops process
henriquealbert opened this issue · comments
Henrique A. Schmaiske commented
Denilson commented
As we discussed in #13062, the Meteor 3 main process now runs inside a promise, meaning that if there is an unhandled rejection inside the app, this main process will be killed.
So, it's best to adopt some conventions when dealing with Promises. For example, you can return this Promise.reject
:
Meteor.methods({
shouldFail: async () => {
return Promise.reject(new Meteor.Error("Oh no!"));
}
});
Another solution would be to throw an error, like:
Meteor.methods({
shouldFail: async () => {
throw new Meteor.Error("Oh no!"));
}
});
You can also add an unhandledRejection
event in your project:
process.on("unhandledRejection", (e) =>
console.error("Unhandled promise rejection:", e.stack || e)
);
I'm closing this issue, and we can keep discussing it if needed.