mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Adjust client safe error handling based on PR review
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user