Skip to content

Commit

Permalink
server/track: always consume the response body for a track request (#131
Browse files Browse the repository at this point in the history
)

* server/track: always consume the response body for a track requeest

Some cloud providers track fetch concurrency and rely on reading
the body to consider a fetch completed.

* Bump package version
  • Loading branch information
MaxLeiter authored Feb 15, 2024
1 parent c55544d commit 8b1c58f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vercel/analytics",
"version": "1.1.3",
"version": "1.1.4",
"description": "Gain real-time traffic insights with Vercel Web Analytics",
"keywords": [
"analytics",
Expand Down
18 changes: 11 additions & 7 deletions packages/web/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,17 @@ export async function track(
},
body: JSON.stringify(body),
method: 'POST',
}).catch((err: unknown) => {
if (err instanceof Error && 'response' in err) {
console.error(err.response);
} else {
console.error(err);
}
});
})
// We want to always consume to body; some cloud providers track fetch concurrency
// and may not release the connection until the body is consumed.
.then((response) => response.text())
.catch((err: unknown) => {
if (err instanceof Error && 'response' in err) {
console.error(err.response);
} else {
console.error(err);
}
});

if (requestContext?.waitUntil) {
requestContext.waitUntil(promise);
Expand Down

0 comments on commit 8b1c58f

Please sign in to comment.