Skip to content

Commit

Permalink
Merge branch 'main' into add-support-for-server-side-props
Browse files Browse the repository at this point in the history
  • Loading branch information
schehata committed Jan 31, 2023
2 parents a64107b + 8f274f1 commit e55bbc3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/logger.ts
Expand Up @@ -151,18 +151,23 @@ export class Logger {
}
const reqOptions: RequestInit = { body, method, keepalive, headers };

function sendFallback() {
// Do not leak network errors; does not affect the running app
fetch(url, reqOptions).catch(console.error);
}

try {
if (typeof fetch === 'undefined') {
const fetch = await require('whatwg-fetch');
await fetch(url, reqOptions);
fetch(url, reqOptions).catch(console.error);
} else if (config.isBrowser && isVercel && navigator.sendBeacon) {
// sendBeacon fails if message size is greater than 64kb, so
// we fall back to fetch.
if (!navigator.sendBeacon(url, body)) {
await fetch(url, reqOptions);
sendFallback();
}
} else {
await fetch(url, reqOptions);
sendFallback();
}
} catch (e) {
console.error(`Failed to send logs to Axiom: ${e}`);
Expand Down

0 comments on commit e55bbc3

Please sign in to comment.