mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
blueslip: Add mechanism for reporting additional information
(imported from commit 738bd3b8800e3b67497755580a2b7ccf66bb3829)
This commit is contained in:
@@ -37,8 +37,10 @@ function report_error(msg, stack, opts) {
|
|||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/json/report_error',
|
url: '/json/report_error',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: { message: msg, stacktrace: stack,
|
data: { message: msg,
|
||||||
|
stacktrace: stack,
|
||||||
ui_message: opts.show_ui_msg,
|
ui_message: opts.show_ui_msg,
|
||||||
|
more_info: JSON.stringify(opts.more_info),
|
||||||
user_agent: window.navigator.userAgent},
|
user_agent: window.navigator.userAgent},
|
||||||
timeout: 3*1000,
|
timeout: 3*1000,
|
||||||
success: function () {
|
success: function () {
|
||||||
@@ -78,8 +80,12 @@ function report_error(msg, stack, opts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function BlueslipError() {
|
function BlueslipError(msg, more_info) {
|
||||||
return Error.apply(this, arguments);
|
var self = Error.call(this, msg);
|
||||||
|
if (more_info !== undefined) {
|
||||||
|
self.more_info = more_info;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlueslipError.prototype = Error.prototype;
|
BlueslipError.prototype = Error.prototype;
|
||||||
@@ -233,36 +239,49 @@ exports.wrap_function = function blueslip_wrap_function(func) {
|
|||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
exports.log = function blueslip_log (msg) {
|
exports.log = function blueslip_log (msg, more_info) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
if (more_info !== undefined) {
|
||||||
|
console.log("Additional information: ", more_info);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.info = function blueslip_info (msg) {
|
exports.info = function blueslip_info (msg, more_info) {
|
||||||
console.info(msg);
|
console.info(msg);
|
||||||
|
if (more_info !== undefined) {
|
||||||
|
console.info("Additional information: ", more_info);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.warn = function blueslip_warn (msg) {
|
exports.warn = function blueslip_warn (msg, more_info) {
|
||||||
console.warn(msg);
|
console.warn(msg);
|
||||||
if (page_params.debug_mode) {
|
if (page_params.debug_mode) {
|
||||||
console.trace();
|
console.trace();
|
||||||
}
|
}
|
||||||
|
if (more_info !== undefined) {
|
||||||
|
console.warn("Additional information: ", more_info);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.error = function blueslip_error (msg) {
|
exports.error = function blueslip_error (msg, more_info) {
|
||||||
if (page_params.debug_mode) {
|
if (page_params.debug_mode) {
|
||||||
throw new BlueslipError(msg);
|
throw new BlueslipError(msg, more_info);
|
||||||
} else {
|
} else {
|
||||||
console.error(msg);
|
console.error(msg);
|
||||||
report_error(msg, Error().stack);
|
if (more_info !== undefined) {
|
||||||
|
console.error("Additional information: ", more_info);
|
||||||
|
}
|
||||||
|
report_error(msg, Error().stack, {more_info: more_info});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.fatal = function blueslip_fatal (msg) {
|
exports.fatal = function blueslip_fatal (msg, more_info) {
|
||||||
if (! page_params.debug_mode) {
|
if (! page_params.debug_mode) {
|
||||||
report_error(msg, Error().stack, {show_ui_msg: true});
|
report_error(msg, Error().stack, {show_ui_msg: true,
|
||||||
|
more_info: more_info});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new BlueslipError(msg);
|
throw new BlueslipError(msg, more_info);
|
||||||
};
|
};
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
|
|||||||
@@ -1527,7 +1527,8 @@ if not (settings.DEBUG or settings.TEST_SUITE):
|
|||||||
@authenticated_json_post_view
|
@authenticated_json_post_view
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def json_report_error(request, user_profile, message=POST, stacktrace=POST,
|
def json_report_error(request, user_profile, message=POST, stacktrace=POST,
|
||||||
ui_message=POST(converter=json_to_bool), user_agent=POST):
|
ui_message=POST(converter=json_to_bool), user_agent=POST,
|
||||||
|
more_info=POST(converter=json_to_dict, default=None)):
|
||||||
subject = "error for %s" % (user_profile.email,)
|
subject = "error for %s" % (user_profile.email,)
|
||||||
if ui_message:
|
if ui_message:
|
||||||
subject = "User-visible browser " + subject
|
subject = "User-visible browser " + subject
|
||||||
@@ -1537,10 +1538,16 @@ def json_report_error(request, user_profile, message=POST, stacktrace=POST,
|
|||||||
if js_source_map:
|
if js_source_map:
|
||||||
stacktrace = js_source_map.annotate_stacktrace(stacktrace)
|
stacktrace = js_source_map.annotate_stacktrace(stacktrace)
|
||||||
|
|
||||||
mail_admins(subject,
|
body = ("Message:\n%s\n\nStacktrace:\n%s\n\nUser agent:\n%s\n\n"
|
||||||
"Message:\n%s\n\nStacktrace:\n%s\n\nUser agent:\n%s\n\n"
|
|
||||||
"User saw error in UI: %s"
|
"User saw error in UI: %s"
|
||||||
% (message, stacktrace, user_agent, ui_message))
|
% (message, stacktrace, user_agent, ui_message))
|
||||||
|
|
||||||
|
if more_info is not None:
|
||||||
|
body += "\n\nAdditional information:"
|
||||||
|
for (key, value) in more_info.iteritems():
|
||||||
|
body += "\n %s: %s" % (key, value)
|
||||||
|
|
||||||
|
mail_admins(subject, body)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@authenticated_json_post_view
|
@authenticated_json_post_view
|
||||||
|
|||||||
Reference in New Issue
Block a user