]> git.wh0rd.org - tt-rss.git/commitdiff
improve JS error logging with additional stuff
authorAndrew Dolgov <noreply@fakecake.org>
Sun, 5 Mar 2017 07:50:15 +0000 (10:50 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Sun, 5 Mar 2017 07:50:15 +0000 (10:50 +0300)
classes/rpc.php
js/functions.js

index 2a92eadbd3b607f2703d90c36d58011503e1f73c..fd10a3a496b70d0a859333e746e84d0fe725a641 100755 (executable)
@@ -647,14 +647,19 @@ class RPC extends Handler_Protected {
        }
 
        function log() {
-               $logmsg = $this->dbh->escape_string($_REQUEST['logmsg']);
+               $msg = $this->dbh->escape_string($_REQUEST['msg']);
+               $file = $this->dbh->escape_string(basename($_REQUEST['file']));
+               $line = (int) $_REQUEST['line'];
+               $context = $this->dbh->escape_string($_REQUEST['context']);
 
-               if ($logmsg) {
+               if ($msg) {
                        Logger::get()->log_error(E_USER_WARNING,
-                               $logmsg, '[client-js]', 0, false);
-               }
+                               $msg, 'client-js:' . $file, $line, $context);
 
-               echo json_encode(array("message" => "HOST_ERROR_LOGGED"));
+                       echo json_encode(array("message" => "HOST_ERROR_LOGGED"));
+               } else {
+                       echo json_encode(array("error" => "MESSAGE_NOT_FOUND"));
+               }
 
        }
 }
index ddb27cba156521e3498a85f84ca6e8c23f58bf70..b33c23dc13035073bd6a0e7ccf890652d67637c1 100755 (executable)
@@ -32,31 +32,32 @@ Array.prototype.remove = function(s) {
 
 
 function report_error(message, filename, lineno, colno, error) {
-       exception_error(error);
+       exception_error(error, null, filename, lineno);
 }
 
-function exception_error(e, e_compat) {
+function exception_error(e, e_compat, filename, lineno, colno) {
        if (typeof e == "string") e = e_compat;
 
        if (!e) return; // no exception object, nothing to report.
 
        try {
+               console.error(e);
+               var msg = e.toString();
 
                try {
                        new Ajax.Request("backend.php", {
-                               parameters: {op: "rpc", method: "log", logmsg: msg},
+                               parameters: {op: "rpc", method: "log",
+                                       file: e.fileName ? e.fileName : filename,
+                                       line: e.lineNumber ? e.lineNumber : lineno,
+                                       msg: msg, context: e.stack},
                                onComplete: function (transport) {
-                                       console.log(transport.responseText);
+                                       console.warn(transport.responseText);
                                } });
 
                } catch (e) {
                        console.error("Exception while trying to log the error.", e);
                }
 
-               var msg = e.toString();
-
-               console.error(msg);
-
                var content = "<div class='fatalError'><p>" + msg + "</p>";
 
                if (e.stack) {