-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
79 lines (67 loc) · 2.66 KB
/
index.html
File metadata and controls
79 lines (67 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!doctype html>
<html>
<head>
<title>TrackJS - Axios Global Error Example</title>
</head>
<body class="container">
<h1>TrackJS Axios Integration</h1>
<div>
<p>
TrackJS will integrate with Axios automatically and capture failed network
requests as errors. However, in certain conditions, Axios has extra information
about errors that it can share with TrackJS.
</p>
<p>
These examples show you how to wire this extra data into TrackJS.
</p>
<p>
Inspect page source for details.
</p>
</div>
<script src="https://cdn.trackjs.com/agent/v3/latest/t.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.10.0/axios.min.js"
integrity="sha512-WkZrEcQ5LMyNy6Y2PQf+Tu3vMcsmKKRKuPXtJSTHQJ3mpuvLRlA5dlDDhrrcXfyWr6Z/y3wIMfjfqVFO/gDZYQ=="
crossorigin="anonymous" referrerpolicy="no-referrer">
</script>
<script>
window.TrackJS && TrackJS.install({
token: "demo-token"
});
// This will trigger a "Network Error"
axios.get('https://bad.trackjs.com/');
// TrackJS<>Axios Integration to pass request details to TrackJS
axios.interceptors.response.use(
(response) => response,
(error) => {
// Optional: Log request headers (be careful with sensitive data!)
if (error.config && error.config.headers) {
TrackJS.console.info({
"request": {
headers: error.config.headers,
body: error.config.data
}
});
}
// Optional: Log response details if available (be careful with sensitive data!)
if (error.response) {
TrackJS.console.info({
"response": {
headers: error.response.headers,
body: error.response.data
}
});
}
// Capture formatted error with method and URL
if (error.config && error.config.method && error.config.url) {
TrackJS.track(`Network Error ${error.config.method.toUpperCase()}: ${error.config.url}`);
} else {
TrackJS.track(error);
}
return Promise.reject(error);
}
);
// This will trigger a detailed "Network Error GET: https://bad2.trackjs.com/"
axios.get('https://bad2.trackjs.com/');
</script>
</body>
</html>