简体   繁体   中英

Error vs Meteor.Error

What is the difference between throw new Error and using Meteor.Error() ? Is it simply that throw new Error will not be shown to the client, only on the server (the client will get a 500 Internal server error); and Meteor.Error will be sent to the client.

Are there any more differences? Eg Does one break out of Fibers, stops downstream code?

The main thing with Meteor.Error is like you mentioned

  • A full stack trace (may not be given by Error always)
  • Possibility to send the error down to the client, in a limited non revealing form.
  • Hide the error from the server in certain cases (if its thrown in a method or publish method, and from hooks such as Accounts.onLoginAttempt )
  • The objects inside are EJSON serialised so a variety of data can be sent down to the client
  • When a Meteor.Error is thrown, because of the EJSON serialisation you get a bit more information on the server side.
  • Meteor displays the errors better. Often you can get [Object object] as the reason to be displayed from ordinary errors when they come from ordinary Errors, from Meteor.wrapAsync

Theres not much else that's different, Meteor.Error is aa subclass of Error with the above changes.

So they'll both stop downstream code. When it comes to Fibers, if the ordinary one is thrown out of a Fiber in any way its likely to stop your app (on the server side & not in a method , startup , Meteor.setInterval , publish , etc)

Its definition is also quite small: https://github.com/meteor/meteor/blob/devel/packages/meteor/errors.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM