Skip to content

Commit

Permalink
Do not even try to clone a websocket response (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettimus authored Jun 10, 2024
1 parent 5117a5e commit 9cd4d39
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions client-library/src/request-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,21 @@ export async function log(
resHeaders[key] = value;
});

const isWebSocket = c.res.status === 101;

// Clone the response so the original isn't affected when we read the body
let body: string;
try {
const clonedResponse = c.res.clone();
// TODO - Read based off of content-type header
body = await clonedResponse.text();
} catch (error) {
// TODO - Check when this fails
console.error("Error reading response body:", error);
body = "__COULD_NOT_PARSE_BODY__";
let body: string | undefined;

if (!isWebSocket) {
try {
const clonedResponse = c.res.clone();
// TODO - Read based off of content-type header
body = await clonedResponse.text();
} catch (error) {
// TODO - Check when this fails
console.error("Error reading response body:", error);
body = "__COULD_NOT_PARSE_BODY__";
}
}

// NOTE - Use errFn (console.error) if the status is 4xx or 5xx
Expand Down

0 comments on commit 9cd4d39

Please sign in to comment.