I am throwing a Meteor.Error exception from a server-side method.
throw new Meteor.Error( 500, 'There was an error processing your request' );
My goal is get the client side Meteor.call to receive this error, which it does, but throwing also causes the node process to exit.
error: Forever detected script exited with code: 8
What is the correct way to signal errors from a Meteor.methods() to a Meteor.call without killing the script?
This can happen if you throw your method from outside the fiber of your method somehow. For example
Meteor.methods({
test: function() {
setTimeout(function() {
throw new Meteor.Error( 500, 'There was an error processing your request' );
}, 0);
}
});
If you are using something that can escape the fiber the method is running in it can cause Meteor to exit.
You just need to make sure where you throw the error it is inside the fiber. (e.g in the above example you can use Meteor.setTimeout
instead of setTimeout
.
If you are using an npm
module you should use Meteor.bindEnvironment for the callbacks. or Meteor.wrapAsync to ensure that the callbacks run in the same fiber.
Once you do this your app should not crash and won't cause forevever to restart it.
The first argument should be a string not an integer in meteor 1.2.1
http://docs.meteor.com/#/full/meteor_error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With