Login

ajax error sink

Author:
amitu
Posted:
October 14, 2008
Language:
JavaScript
Version:
Not specified
Tags:
ajax jquery error reporting
Score:
5 (after 5 ratings)

Often its useful to get error information for ajax/javascript errors happening on various clients. This can go to something like this:

# error_sink
def error_sink(request):
    # post request, with event name in "event", and event data in "data"
    context = request.REQUEST.get("context", "")    
    context = cgi.parse_qs(context)
    context["data"] = cgi.parse_qs(context.get("data", [""])[0])
    context["user"] = request.vuser
    context["referrer"] = request.META.get('HTTP_REFERER', "referrer not set")
    context = pformat(context)
    send_mail(
        "ajax error", context, "no-reply@example.com",
        ["me@example.com",], fail_silently=True
    )    
    return JSONResponse({"status": "ok" })
# }}}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function error_sink(req, msg, err_obj){
    var context = { url: this.url };
    context["data"] =  this.data;
    context["timeout"]= this.timeout;
    context["msg"] =  msg;
    context["error"] = err_obj;
    context["time"] = Date().toString();
    jQuery.get('/ajax/error-sink/', jQuery.param({ context: jQuery.param(context) }));
};

jQuery(function($){
    $.ajaxSetup({error: error_sink});
});

More like this

  1. View decorator to convert DoesNotExist (ObjectDoesNotExist) exceptions into Http404 exceptions by jammycakes 5 years, 8 months ago
  2. ajax_validator generic view by amitu 6 years, 7 months ago
  3. ajax protocol for data by limodou 8 years, 3 months ago
  4. Javascript HTTP response by davep 7 years, 10 months ago
  5. mask_email filter by jkocherhans 8 years, 2 months ago

Comments

Please login first before commenting.