Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Catch external HXR and Javascript errors from the console

I am building a small tool for a no-code platform that I wish can send all the errors from the front-end to a server. Here's the code I wrote so far to get the errors during run-time:

// In this function I want to catch XHR (APIs) errors and other general errors
document.addEventListener("DOMContentLoaded", function(){
    window.onerror = function (msg, source, lineNo, columnNo, error) {
    report_error_bhelper(msg, "onerror")
    }
    
    $.ajaxSetup({
      cache: false,
      error: function(jqXHR, exception) {
      var msg = jqXHR + exception
      report_error_bhelper(msg, "XHR")
      }
  });
});

// In this function I catch all "error" and "warn" console logs
(function() {
    var exError = console.error;
    var exWarn = console.warn;
    console.error = function(msg) {
        exError.apply(this, arguments);
        console.log('Error detected, loggin error to Bubble Helper...')
        report_error_bhelper(msg, "error")
    }
        console.warn = function(msg) {
        exWarn.apply(this, arguments);
        console.log('Warning detected, loggin error to Bubble Helper...')
        report_error_bhelper(msg, "warn")
    }
})()

The second part of the code works really well and I got all my errors sent, but I am not able to catch other errors, especially when HXR requests fails.

I am missing something? I would love some tips!

I've tried implementing the "window.onerror" at different level (when DOM is loaded, raw in the code, ...) but it seems like I won't get the errors

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!