drivly / ctx.do

Context Enrichment API
https://ctx.do
MIT License
6 stars 1 forks source link

Make CTX.do more defensive #36

Closed nathanclevenger closed 1 year ago

nathanclevenger commented 2 years ago

We can't afford for anything to make ctx.do stop working because it breaks so many things now.

So, we need to make a few changes:

  1. We need to declare all of the variables as let x = undefined at the top outside a try/catch block
  2. We need to hydrate all of the objects, in progressive levels of complexity/risk, wrapped with a try/catch block
  3. We need to ensure that we don't assume any object/field exists ... even including and especially fields like cf.[whatever] because those can break, and in fact in certain situations (like Workers for Platforms), the cf object is never hydrated
  4. The response to JSON needs to be outside the try/catch block, so if there is an exception, we are still able to respond with the basics
  5. Errors in ctx.do should be logged to Sentry and/or Slack as emergency alerts (see #35)

There are some other refactors we'll probably need to do, like moving the user object construction into separate above variables instead of the on-demand construction that is currently happening.

sam-lippert commented 1 year ago

Completed in https://github.com/drivly/ctx.do/commit/1df6e069be46b293c64fcd81d65f6fe44d91edd6 (minus #35, tracked separately)