Login

ajax error sink

Author:
amitu
Posted:
October 14, 2008
Language:
JavaScript
Version:
Not specified
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, "[email protected]",
        ["[email protected]",], 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. Django Collapsed Stacked Inlines by applecat 1 year, 9 months ago
  2. Django Collapsed Stacked Inlines by mkarajohn 3 years, 10 months ago
  3. Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 6 months ago
  4. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 7 months ago
  5. Django admin inline ordering - javascript only implementation by ojhilt 11 years, 11 months ago

Comments

Please login first before commenting.