In Meteor, what is difference between this.error and throw new Meteor.Error in Meteor.publish?

meteor

Solution

`this.error` is only available inside the publish method. Per the docs:

Stops this client's subscription, triggering a call on the client to the `onError` callback passed to `Meteor.subscribe`, if any. If error is not a `Meteor.Error`, it will be mapped to `Meteor.Error(500, "Internal server error")`.

Throwing a `Meteor.Error` would not stop the client's subscription, it would just terminate execution and raise the exception. So if you want to ensure Meteor will clean up after you and allow you to handle the error on the client when something unexpected happens, it's recommended to use `this.error` rather than throwing your own inside the publish method.

Problem

In `Meteor.publish`, what is a difference between using `this.error` and simply throwing an `Meteor.Error`?

Original source