mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
Send browser errors back to the server
(imported from commit 8c676017e8b3fc4f17552db15d32266099dba8f2)
This commit is contained in:
@@ -74,6 +74,7 @@ urlpatterns = patterns('',
|
||||
url(r'^json/tutorial_send_message$', 'zephyr.views.json_tutorial_send_message'),
|
||||
url(r'^json/change_enter_sends$', 'zephyr.views.json_change_enter_sends'),
|
||||
url(r'^json/get_profile$', 'zephyr.views.json_get_profile'),
|
||||
url(r'^json/report_error$', 'zephyr.views.json_report_error'),
|
||||
|
||||
# These are json format views used by the API. They require an API key.
|
||||
url(r'^api/v1/get_messages$', 'zephyr.tornadoviews.api_get_messages'),
|
||||
|
||||
@@ -5,6 +5,25 @@ var blueslip = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
var error_has_stack = Error().hasOwnProperty('stack');
|
||||
|
||||
function report_error(msg) {
|
||||
var stack;
|
||||
if (error_has_stack) {
|
||||
stack = Error().stack;
|
||||
} else {
|
||||
stack = 'No stacktrace available';
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/json/report_error',
|
||||
dataType: 'json',
|
||||
data: { message: msg, stacktrace: stack },
|
||||
timeout: 10*1000
|
||||
});
|
||||
}
|
||||
|
||||
exports.log = function blueslip_log (msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
@@ -25,10 +44,15 @@ exports.error = function blueslip_error (msg) {
|
||||
throw new Error(msg);
|
||||
} else {
|
||||
console.error(msg);
|
||||
report_error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
exports.fatal = function blueslip_fatal (msg) {
|
||||
if (! debug_mode) {
|
||||
report_error(msg);
|
||||
}
|
||||
|
||||
throw new Error(msg);
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from django.core import validators
|
||||
from django.contrib.auth.views import login as django_login_page, \
|
||||
logout_then_login as django_logout_then_login
|
||||
from django.db.models import Q
|
||||
from django.core.mail import send_mail
|
||||
from django.core.mail import send_mail, mail_admins
|
||||
from zephyr.models import Message, UserProfile, Stream, Subscription, \
|
||||
Recipient, get_huddle, Realm, UserMessage, \
|
||||
PreregistrationUser, get_client, MitUser, User, UserActivity, \
|
||||
@@ -1403,3 +1403,10 @@ def json_update_active_status(request, user_profile,
|
||||
@authenticated_json_post_view
|
||||
def json_get_active_statuses(request, user_profile):
|
||||
return get_status_list(user_profile)
|
||||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_report_error(request, user_profile, message=POST, stacktrace=POST):
|
||||
mail_admins("Browser error for %s" % (user_profile.user.email,),
|
||||
"Message:\n%s\n\nStacktrace:\n%s" % (message, stacktrace))
|
||||
return json_success()
|
||||
|
||||
Reference in New Issue
Block a user