Skip to content

Commit

Permalink
Fix error/info log
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-lippert committed Sep 19, 2023
1 parent cec2a90 commit dae397e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
19 changes: 8 additions & 11 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export default {
fetch: async (req, env, ctx) => {
async function logMongo(data, isError = false) {
if (isError) {
console.error('彡', 'logs.logs.ctx.do', data)
} else {
console.log('彡', 'logs.errors.ctx.do', data)
} else {
console.error('彡', 'logs.logs.ctx.do', data)
}
if (env.MONGO_ENDPOINT)
return await fetch(env.MONGO_ENDPOINT + '/action/insertOne', {
Expand Down Expand Up @@ -194,7 +194,7 @@ export default {
}))
}
await Promise.all(processes)
const retval = JSON.stringify(
const retval =
{
api,
colo,
Expand Down Expand Up @@ -273,12 +273,9 @@ export default {
recentInteractions: interactionCounter[ip],
trustScore: profile ? 99 : cf?.botManagement?.score,
},
},
null,
2
)
}
ctx.waitUntil(logMongo(retval))
return new Response(method === 'HEAD' ? null : retval, {
return new Response(method === 'HEAD' ? null : JSON.stringify(retval, null, 2), {
headers: {
'content-type': 'application/json; charset=utf-8',
},
Expand All @@ -287,7 +284,7 @@ export default {
const { name, message, trace } = err
const error = { name, message, trace }
console.log({ name, message, trace, err })
const errorBody = JSON.stringify({
const errorBody = {
api,
error,
colo,
Expand Down Expand Up @@ -366,9 +363,9 @@ export default {
recentInteractions: interactionCounter[ip],
trustScore: profile ? 99 : cf?.botManagement?.score,
},
}, null, 2)
}
ctx.waitUntil(logMongo(errorBody, true))
return new Response(errorBody, {
return new Response(JSON.stringify(errorBody, null, 2), {
headers: {
'content-type': 'application/json; charset=utf-8',
},
Expand Down
3 changes: 0 additions & 3 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ services = [
{ binding = "APIKEYS", service = "apikeys-do", environment = "production" },
{ binding = "JWT", service = "jwt-do", environment = "production" }
]

[[analytics_engine_datasets]]
binding = "INTERACTIONS"

0 comments on commit dae397e

Please sign in to comment.