Skip to content

Commit cf5fd59

Browse files
committed
Handle error
1 parent 85579cf commit cf5fd59

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

index.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,25 @@ async function start() {
3939

4040
async function getMetric(metric) {
4141
const url = `https://analytics.services.netlify.com/v1/${siteId}/${metric}?from=${startDate.getTime().toFixed()}&to=${endDate.getTime()}&timezone=${timezone}&resolution=day`;
42-
var res = await fetch(url, {
43-
"credentials": "include",
44-
"headers": {
45-
"Content-Type": "application/json",
46-
"Authorization": `Bearer ${token}`,
47-
"Pragma": "no-cache",
48-
"Cache-Control": "no-cache"
49-
},
50-
"method": "GET",
51-
"mode": "cors"
52-
});
53-
54-
const response = await res.json();
55-
writeToCSV(response.data, metric);
42+
try {
43+
var res = await fetch(url, {
44+
"credentials": "include",
45+
"headers": {
46+
"Content-Type": "application/json",
47+
"Authorization": `Bearer ${token}`,
48+
"Pragma": "no-cache",
49+
"Cache-Control": "no-cache"
50+
},
51+
"method": "GET",
52+
"mode": "cors"
53+
});
54+
55+
const response = await res.json();
56+
writeToCSV(response.data, metric);
57+
} catch(e) {
58+
console.error("Request failed". url);
59+
console.error(e);
60+
}
5661
}
5762

5863
function writeToCSV(data, metric) {

0 commit comments

Comments
 (0)