Skip to content

Commit

Permalink
fix: try/catch logHttpRequest (#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcoraven authored Sep 19, 2023
1 parent 903145a commit c54db48
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
42 changes: 23 additions & 19 deletions packages/service-utils/src/cf-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,27 @@ export async function logHttpRequest({
isAuthed?: boolean;
statusMessage?: Error | string;
}) {
const authorizationData = await extractAuthorizationData({ req, clientId });
const headers = req.headers;

console.log(
JSON.stringify({
source,
pathname: req.url,
hasSecretKey: !!authorizationData.secretKey,
hasClientId: !!authorizationData.clientId,
hasJwt: !!authorizationData.jwt,
clientId: authorizationData.clientId,
isAuthed: !!isAuthed ?? null,
status: res.status,
sdkName: headers.get("x-sdk-name") ?? "unknown",
sdkVersion: headers.get("x-sdk-version") ?? "unknown",
platform: headers.get("x-sdk-platform") ?? "unknown",
}),
);
console.log(`statusMessage=${statusMessage ?? res.statusText}`);
try {
const authorizationData = await extractAuthorizationData({ req, clientId });
const headers = req.headers;

console.log(
JSON.stringify({
source,
pathname: req.url,
hasSecretKey: !!authorizationData.secretKey,
hasClientId: !!authorizationData.clientId,
hasJwt: !!authorizationData.jwt,
clientId: authorizationData.clientId,
isAuthed: !!isAuthed ?? null,
status: res.status,
sdkName: headers.get("x-sdk-name") ?? "unknown",
sdkVersion: headers.get("x-sdk-version") ?? "unknown",
platform: headers.get("x-sdk-platform") ?? "unknown",
}),
);
console.log(`statusMessage=${statusMessage ?? res.statusText}`);
} catch (err) {
console.error("Failed to log HTTP request:", err);
}
}
46 changes: 25 additions & 21 deletions packages/service-utils/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,29 @@ export function logHttpRequest({
isAuthed?: boolean;
statusMessage?: Error | string;
}) {
const authorizationData = extractAuthorizationData({ req, clientId });
const headers = req.headers;

const _statusMessage = statusMessage ?? res.statusMessage;
console.log(
JSON.stringify({
source,
pathname: req.url,
hasSecretKey: !!authorizationData.secretKey,
hasClientId: !!authorizationData.clientId,
hasJwt: !!authorizationData.jwt,
clientId: authorizationData.clientId,
isAuthed: !!isAuthed ?? null,
status: res.statusCode,
statusMessage: _statusMessage,
sdkName: headers["x-sdk-name"] ?? "unknown",
sdkVersion: headers["x-sdk-version"] ?? "unknown",
platform: headers["x-sdk-platform"] ?? "unknown",
}),
);
console.log(`statusMessage=${_statusMessage}`);
try {
const authorizationData = extractAuthorizationData({ req, clientId });
const headers = req.headers;

const _statusMessage = statusMessage ?? res.statusMessage;
console.log(
JSON.stringify({
source,
pathname: req.url,
hasSecretKey: !!authorizationData.secretKey,
hasClientId: !!authorizationData.clientId,
hasJwt: !!authorizationData.jwt,
clientId: authorizationData.clientId,
isAuthed: !!isAuthed ?? null,
status: res.statusCode,
statusMessage: _statusMessage,
sdkName: headers["x-sdk-name"] ?? "unknown",
sdkVersion: headers["x-sdk-version"] ?? "unknown",
platform: headers["x-sdk-platform"] ?? "unknown",
}),
);
console.log(`statusMessage=${_statusMessage}`);
} catch (err) {
console.error("Failed to log HTTP request:", err);
}
}

0 comments on commit c54db48

Please sign in to comment.