Created
December 11, 2019 14:53
-
-
Save ziadoz/0c4c0e27fb096332f4d086595fda2309 to your computer and use it in GitHub Desktop.
Log JS Errors via AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // On error send to backend route which will log error into central logging service. | |
| window.onerror = function(message, file, line) { | |
| fetch( | |
| '/log/js-error', | |
| { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify({ | |
| file: file, | |
| line: line, | |
| message: message, | |
| browser: navigator.userAgent, | |
| url: window.location.href | |
| }) | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment