title: How to log all possible console errors occurring in Angular application on a client's side?
body: <p>Currently, my Angular application consists of a significant number of submodules and components. Angular applications are quite sensitive to html rendering errors. For example, if we get a NULL object from an API and trying to get access to its property, it partially breaks rendering of the application. </p>
  
  <p>It is quite difficult to handle and test such cases taking into account that the application is constantly growing. Do you know if it is possible to create a script that can log all error appearing in a console? </p>
  
  <p>Here what I have got: </p>
  
  <p>1) <strong>An http requests error handle</strong> to log broken requests from an API:</p>
  
  <pre><code>  private handleError&lt;T&gt; (operation = 'operation', result?: T) {
      return (error: any): Observable&lt;T&gt; =&gt; {
  
        // TODO: send the error to remote logging infrastructure
        console.error(error); // log to console instead
  
        // TODO: better job of transforming error for user consumption
        this.log(`${operation} failed: ${error.message}`);
  
        // Let the app keep running by returning an empty result.
        return of(result as T);
      };
    }
  </code></pre>
  
  <p>2) <strong>Client-side logger</strong> but for whatever reason it only logs errors from crawlers :) </p>
  
  <pre><code>&lt;script&gt;
    window.onerror = function(m,u,l,c) {
      if (window.XMLHttpRequest) {
        var xhr = new XMLHttpRequest();
        var data = "msg="+encodeURIComponent(m)
          +"&amp;url="+encodeURIComponent(u)
          +"&amp;line="+l
          +"&amp;col="+c
          +"&amp;href="+encodeURIComponent(window.location.href);
        xhr.open("GET", "logger.php?"+data, true);
        xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
        xhr.send();
      }
    };
  &lt;/script&gt;
  </code></pre>
  
  <p>It would be very useful to get a script that can simply log all errors from console and </p>