cognovi-ai / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling and reframing distorted thinking when you've been thinking this way your whole life. The CDJ can help with that 🧠✨ -- v2 is in development!
https://thecdj.app
4 stars 0 forks source link

Add server side logging to ExpressError and new Error types. #184

Open hiyaryan opened 3 weeks ago

hiyaryan commented 3 weeks ago

TODO added to line 116 of requestBetaAccess function in middelware/access.ts

TODO: Add server-side logging for errors; Expand ExpressError to include a log method to log errors from catch blocks to a file.

eslint-disable-next-line @typescript-eslint/no-unused-vars ESLint disable comment used to allow err caught in catch block to not be used. The catch block simply passes an ExpressError to the error handler without using the runtime error stored in err.

This suggests that ExpressError can be expanded to include a logging feature as described in the TODO.

davidzlu commented 3 weeks ago

We might also want to consider having more elaborate typing for errors going forward, instead of having ExpressError as the catch-all. It increases complexity, but also lets you handle them more precisely. We also should take a look at the JS logging libraries out there and try integrating them rather than settling on console.log.

hiyaryan commented 1 week ago

Note that the new services layer is printing errors to the console with console.error. This makes the output in the console very verbose.

Instead of logging the error to the console, the error should be logged in a file and timestamped. The morgan error should also be timestamped. Then whenever a server side error code ≥ 500 occurs, for example, the morgan error can be traced to the error in the log.

Note that morgan middleware does not have to be used if another logger is preferred for HTTP request/response logging.

187