Added throwStubExceptions option to Meteor.call

Allows method simulations to be used as validators and enables freely throwing exceptions in method definitions without worrying about spurious logging on the client.
This commit is contained in:
Tom Coleman
2015-04-15 17:42:14 +10:00
committed by David Glasser
parent 5a512ea990
commit d758441cf4
2 changed files with 22 additions and 4 deletions

View File

@@ -823,13 +823,18 @@ _.extend(Connection.prototype, {
// If an exception occurred in a stub, and we're ignoring it
// because we're doing an RPC and want to use what the server
// returns instead, log it so the developer knows.
// returns instead, log it so the developer knows
// (unless they explicitly ask to see the error).
//
// Tests can set the 'expected' flag on an exception so it won't
// go to log.
if (exception && !exception.expected) {
Meteor._debug("Exception while simulating the effect of invoking '" +
name + "'", exception, exception.stack);
if (exception) {
if (options.throwStubExceptions) {
throw exception;
} else if (!exception.expected) {
Meteor._debug("Exception while simulating the effect of invoking '" +
name + "'", exception, exception.stack);
}
}

View File

@@ -193,6 +193,19 @@ testAsyncMulti("livedata - basic method invocation", [
test.equal(Meteor.call("exception", "both"), undefined);
test.equal(Meteor.call("exception", "server"), undefined);
test.equal(Meteor.call("exception", "client"), undefined);
// If we pass throwStubExceptions then we *should* see thrown exceptions
// on the client
test.throws(function () {
Meteor.apply("exception", ["both"], {throwStubExceptions: true});
});
test.equal(
Meteor.apply("exception", ["server"], {throwStubExceptions: true}),
undefined);
test.throws(function () {
Meteor.apply("exception", ["client"], {throwStubExceptions: true});
});
}
// With callback