How to catch JavaScript Errors with window.onerror


I’m working on a new responsive website for company that has a fair amount of JavaScript and  that is viewed in lots of different browsers (mobile, tablet, desktop). 
Naturally we want to log our JavaScript exceptions and their stacktraces,  just like we log server-side exceptions. 
It is impossible to test every combination of device and browser so we rely on logging to find the edge cases we miss in our testing.

The way we handle our JavaScript exceptions is to:

 catch the exception.
 collect data about the useragent.

 Save it to our logs by sending an ajax request with the data and the exception information.


$(window).error(function (msg, url, line) 
{   
errorlog(msg.originalEvent.error);
    });



function errorlog(e) { if (typeof (e) == "object") { e.searchurl = location.href; } else if (typeof (e) == "string") { e += "SearchUrl" + location.href; } $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: location.protocol + "//" + location.hostname + "/" + location.pathname + "/errorlog", data: JSON.stringify({ _jsexception: e.stack }), dataType: "json", async: true, success: function (data, textStatus) { if (textStatus == "success") { if (data.hasOwnProperty("d")) { msg = data.d; } else { msg = data; } } }, error: function (data, status, error) { } }); }



Code behind
---------------------------------------------
[System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static void errorlog(object _jsexception)
        {
            string strEmailBody = string.Empty;

            if (_jsexception.GetType().Name == "String")
            {
                strEmailBody += "
Method Name:- Error " + _jsexception as string;

            }
            else
            {
                Dictionary dicErrorAttribute = _jsexception as Dictionary;
                foreach (var _keyandvalue in dicErrorAttribute)
                {
                    if (_keyandvalue.Key == "name")
                    {
                        strEmailBody += "
Method Name:- " + _keyandvalue.Value;

                    }
                    else
                    {
                        strEmailBody += "
" + _keyandvalue.Key + ":- " + _keyandvalue.Value;

                    }
                }
            }
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
            using (con)
            {
                SqlCommand cmd = new SqlCommand("proc_Error", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Subject", "Error On JavaScript"));
                cmd.Parameters.Add(new SqlParameter("@Body", strEmailBody));
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }

        }




1. Step

npm uninstall @angular/cli -g 


2. step

Cleared cache


3. step

Manually deleted content in
%AppData%\npm\node_modules

4.  step

npm install -g @angular/cli@latest




What are callbacks?

A callback is just a way to store some things to do at a later time.

A callback function is called at the completion of a given task.

The callback takes two arguments, resolve and reject , which are both functions. All your asynchronous code goes inside that callback. If everything is successful, the promise is fulfilled by calling resolve() . In case of an error, reject() is called with an Error object.


A promise is an object which can be returned synchronously from an asynchronous function. It will be in one of 3 possible states:
Fulfilled: onFulfilled() will be called (e.g., resolve() was called)
Rejected: onRejected() will be called (e.g., reject() was called)
Pending: not yet fulfilled or rejected


Configuring IIS 7.5 to send XML/JSON responses gzipped
-------------------------------------------------------------------------------


call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/serverRuntime /frequentHitThreshold:"1"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/urlCompression /doDynamicCompression:"True"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/json']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/json; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/x-javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/x-javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/x-javascript; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/x-javascript; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='*/*']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='*/*',enabled='False']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/x-javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/x-javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/x-javascript; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/x-javascript; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='*/*']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='*/*',enabled='False']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /noCompressionForHttp10:"False" /noCompressionForProxies:"False" /minFileSizeForComp:"2700"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/atom%u002bxml',enabled='True']" /commit:apphost
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/atom%u002bxml;charset=utf-8',enabled='True']" /commit:apphost


------------------------------------

IIS setting
configuration => system.webServer/httpCompression 




In Request Header :

User-Agent: Fiddler
Content-Type: application/xml
Accet-Encoding: gzip,deflate
Host: 192.168.0.11:82
Content-Length: 577

Next PostNewer Posts Previous PostOlder Posts Home