Browse Source

random: no printear mensajes de error en prod (a lighthouse no le gusta)

pull/1/head
void 3 months ago
parent
commit
e8b339f5b9
5 changed files with 6 additions and 4 deletions
  1. 1
    0
      .env
  2. 1
    0
      Makefile
  3. 1
    1
      public/index.html
  4. 2
    2
      public/lib/papas-dia.js
  5. 1
    1
      public/lib/papas-dia.min.js

+ 1
- 0
.env View File

@@ -1,2 +1,3 @@
1 1
 VUE_APP_GRAPHQL_URL=http://192.168.86.222:4000/
2 2
 VUE_APP_PAPAS_DIA_URL=http://192.168.86.222:1984
3
+VUE_APP_DEBUG=true

+ 1
- 0
Makefile View File

@@ -1,6 +1,7 @@
1 1
 build:
2 2
 	VUE_APP_GRAPHQL_URL=https://api.ninty.homework-manager.ml/ \
3 3
 	  VUE_APP_PAPAS_DIA_URL=https://api.ninty.homework-manager.ml/papasdia \
4
+	  VUE_APP_DEBUG=false \
4 5
 	  pnpm run build
5 6
 
6 7
 deploy:

+ 1
- 1
public/index.html View File

@@ -10,7 +10,7 @@
10 10
     <% if (NODE_ENV === 'production') { %>
11 11
       <script src="<%= BASE_URL %>lib/papas-dia.min.js"></script>
12 12
       <script>
13
-        PapasDia('<%= VUE_APP_PAPAS_DIA_URL %>', 'ninty_web')
13
+        window.PapasDia('<%= VUE_APP_PAPAS_DIA_URL %>', 'ninty_web', <%= VUE_APP_DEBUG %>)
14 14
       </script>
15 15
     <% } %>
16 16
   </head>

+ 2
- 2
public/lib/papas-dia.js View File

@@ -9,7 +9,7 @@ window.PapasDia = (function () {
9 9
     return result
10 10
   }
11 11
 
12
-  function PapasDia (backendUrl, appName) {
12
+  function PapasDia (backendUrl, appName, debugToConsole) {
13 13
     if (!appName) appName = 'app_name_not_defined'
14 14
     this.backendUrl = backendUrl
15 15
     this.appName = appName
@@ -52,7 +52,7 @@ window.PapasDia = (function () {
52 52
 
53 53
     function generateConsoleEventFunction (origFunc, eventType) {
54 54
       return function () {
55
-        origFunc.apply(console, arguments)
55
+        if (debugToConsole) origFunc.apply(console, arguments)
56 56
         addEvent({
57 57
           type: eventType,
58 58
           data: Array.from(arguments),

+ 1
- 1
public/lib/papas-dia.min.js View File

@@ -1 +1 @@
1
-window.PapasDia=function(){function makeId(length){var result="";var characters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";var charactersLength=characters.length;for(var i=0;i<length;i++){result+=characters.charAt(Math.floor(Math.random()*charactersLength))}return result}function PapasDia(backendUrl,appName){if(!appName)appName="app_name_not_defined";this.backendUrl=backendUrl;this.appName=appName;this.id=makeId(10);this.startedSession=Date.now();this.eventsToSend=[];window._addEvent=addEvent;setInterval(sendToServer,1e4);this._log=console.log;console.log=generateConsoleEventFunction(console.log,"log");console.error=generateConsoleEventFunction(console.error,"error");console.info=generateConsoleEventFunction(console.info,"info");console.warn=generateConsoleEventFunction(console.warn,"warn");var _log=this._log;window.onerror=function(errorMsg,url,lineNumber,column,errorObj){addEvent({type:"onerror",msg:errorMsg,url:url,lineNumber:lineNumber,column:column,stack:errorObj&&errorObj.stack});_log("[papas-dia.js] caught onerror");return false};window.onunhandledrejection=function(event){addEvent({type:"onunhandledrejection",event:event});_log("[papas-dia.js] caught onunhandledrejection");return false};function generateConsoleEventFunction(origFunc,eventType){return function(){origFunc.apply(console,arguments);addEvent({type:eventType,data:Array.from(arguments)})}}var self=this;function addEvent(event){self.eventsToSend.push(event)}function sendToServer(){if(self.eventsToSend.length<1)return;var events=self.eventsToSend;self.eventsToSend=[];var request=new XMLHttpRequest;request.onreadystatechange=function(){try{if(request.readyState===XMLHttpRequest.DONE){}}catch(error){self.eventsToSend=self.eventsToSend.concat(events)}};request.open("POST",self.backendUrl+"?appName="+encodeURIComponent(self.appName)+"&id="+encodeURIComponent(self.id)+"&data="+encodeURIComponent(JSON.stringify(events)),true);request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");request.send()}}return PapasDia}();
1
+window.PapasDia=function(){function makeId(length){var result="";var characters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";var charactersLength=characters.length;for(var i=0;i<length;i++){result+=characters.charAt(Math.floor(Math.random()*charactersLength))}return result}function PapasDia(backendUrl,appName,debugToConsole){if(!appName)appName="app_name_not_defined";this.backendUrl=backendUrl;this.appName=appName;this.id=makeId(10);this.startedSession=Date.now();this.eventsToSend=[];window._addEvent=addEvent;setInterval(sendToServer,1e4);this._log=console.log;console.log=generateConsoleEventFunction(console.log,"log");console.error=generateConsoleEventFunction(console.error,"error");console.info=generateConsoleEventFunction(console.info,"info");console.warn=generateConsoleEventFunction(console.warn,"warn");var _log=this._log;window.onerror=function(errorMsg,url,lineNumber,column,errorObj){addEvent({type:"onerror",msg:errorMsg,url:url,lineNumber:lineNumber,column:column,stack:errorObj&&errorObj.stack});_log("[papas-dia.js] caught onerror");return false};window.onunhandledrejection=function(event){addEvent({type:"onunhandledrejection",event:event});_log("[papas-dia.js] caught onunhandledrejection");return false};function generateConsoleEventFunction(origFunc,eventType){return function(){if(debugToConsole)origFunc.apply(console,arguments);addEvent({type:eventType,data:Array.from(arguments)})}}var self=this;function addEvent(event){self.eventsToSend.push(event)}function sendToServer(){if(self.eventsToSend.length<1)return;var events=self.eventsToSend;self.eventsToSend=[];var request=new XMLHttpRequest;request.onreadystatechange=function(){try{if(request.readyState===XMLHttpRequest.DONE){}}catch(error){self.eventsToSend=self.eventsToSend.concat(events)}};request.open("POST",self.backendUrl+"?appName="+encodeURIComponent(self.appName)+"&id="+encodeURIComponent(self.id)+"&data="+encodeURIComponent(JSON.stringify(events)),true);request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");request.send()}}return PapasDia}();

Loading…
Cancel
Save