Advertisement
Guest User

Untitled

a guest
Dec 19th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener('error', (event) => {
  2.     const { message, filename, lineno, colno, error } = event;
  3.     var debug = {
  4.         uuid: device.uuid,
  5.         version: appVersion,
  6.         platform: device.platform,
  7.         message: message,
  8.         filename: filename,
  9.         lineno: lineno,
  10.         colno: colno,
  11.         error: error.stack
  12.     }
  13.     sendError(debug);
  14.     return false;
  15. });
  16.  
  17. function sendError(error) {
  18.  
  19.     let xhr = new XMLHttpRequest();
  20.     let url = "https://yourdomainhere.com/errorAPI";
  21.     xhr.open("POST", url, true);
  22.     xhr.setRequestHeader("Content-Type", "application/json");
  23.     xhr.onreadystatechange = () => {
  24.         // In local files, status is 0 upon success in Mozilla Firefox
  25.         if (xhr.readyState === XMLHttpRequest.DONE) {
  26.             const status = xhr.status;
  27.             if (status === 0 || (status >= 200 && status < 400)) {
  28.                 try {
  29.                     console.log(xhr.responseText)
  30.                     var data = xhr.responseText;
  31.                     data = JSON.parse(data);
  32.                     //do something here with the JSON response, if neccessary
  33.                 } catch (error) {
  34.  
  35.                 }
  36.             } else {
  37.                 try {
  38.                     //Something really went wrong...
  39.                     //emergency code here
  40.                 } catch (error) {
  41.  
  42.                 }
  43.             }
  44.         }
  45.     };
  46.     var data = JSON.stringify(error);
  47.     xhr.send(data);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement