Adjust client safe error handling based on PR review

This commit is contained in:
Eric Dobbertin
2017-06-11 20:39:57 -05:00
parent 532c4b1da4
commit bb8a695aee
2 changed files with 15 additions and 10 deletions

View File

@@ -1724,13 +1724,14 @@ var wrapInternalException = function (exception, context) {
// depend on the Meteor.Error class, `isClientSafe` can be set to true on any
// error before it is thrown.
if (exception.isClientSafe) {
const originalMessage = exception.message;
exception = new Meteor.Error(exception.error, exception.reason, exception.details);
exception.message = originalMessage;
if (!(exception instanceof Meteor.Error)) {
const originalMessage = exception.message;
exception = new Meteor.Error(exception.error, exception.reason, exception.details);
exception.message = originalMessage;
}
return exception;
}
if (exception instanceof Meteor.Error) return exception;
// tests can set the 'expected' flag on an exception so it won't go to the
// server log
if (!exception.expected) {
@@ -1746,10 +1747,10 @@ var wrapInternalException = function (exception, context) {
// provided a "sanitized" version with more context than 500 Internal server
// error? Use that.
if (exception.sanitizedError) {
if (exception.sanitizedError instanceof Meteor.Error)
if (exception.sanitizedError.isClientSafe)
return exception.sanitizedError;
Meteor._debug("Exception " + context + " provides a sanitizedError that " +
"is not a Meteor.Error; ignoring");
"does not have isClientSafe property set; ignoring");
}
return new Meteor.Error(500, "Internal server error");

View File

@@ -47,7 +47,7 @@ Meteor.makeErrorType = function (name, constructor) {
* ```
* // on the server, pick a code unique to this error
* // the reason field should be a useful debug message
* throw new Meteor.Error("logged-out",
* throw new Meteor.Error("logged-out",
* "The user must be logged in to post a comment.");
*
* // on the client
@@ -59,10 +59,10 @@ Meteor.makeErrorType = function (name, constructor) {
* }
* });
* ```
*
*
* For legacy reasons, some built-in Meteor functions such as `check` throw
* errors with a number in this field.
*
*
* @param {String} [reason] Optional. A short human-readable summary of the
* error, like 'Not Found'.
* @param {String} [details] Optional. Additional information about the error,
@@ -73,6 +73,10 @@ Meteor.Error = Meteor.makeErrorType(
function (error, reason, details) {
var self = this;
// Newer versions of DDP use this property to signify that an error
// can be sent back and reconstructed on the calling client.
self.isClientSafe = true;
// String code uniquely identifying this kind of error.
self.error = error;