Include Network Payloads
For privacy reasons, TrackJS doesn’t automatically record the request or response payloads from network errors. However, if that’s something you wish to do, the following code provides a general outline of how that might be accomplished.
First, you’ll want to prevent TrackJS from capturing network errors, as we’ll build a custom handler to catch them.
window.TrackJS && TrackJS.install({
token: "{TOKEN}",
network: { error: false }
});
import { TrackJS } from "trackjs";
TrackJS.install({
token: "{TOKEN}",
network: { error: false }
});
<script>
window._trackJs = {
token: "{TOKEN}",
network: { error: false }
};
</script>
<script src="https://cdn.trackjs.com/releases/current/tracker.js"></script>
Then, we’ll add a custom error handler to your AJAX system. This can vary quite a bit based on your framework. Here is an example using jQuery:
// Attach a callback for when network errors occur $(document).ajaxError(function(evt, xhr, opts, message) { if (!window.TrackJS) { return; } // Safety Check // Log the relevant info to the Telemetry Console TrackJS.console.log({ message: message, method: opts.type, url: opts.url, status: xhr.status, statusText: xhr.statusText, request: opts.data, response: xhr.responseText }); // Record the Error TrackJS.track(xhr.status + " " + xhr.statusText + ": " + opts.type + " " + url); });