Context
The analytics auto-capture middleware registers a res.on('finish') handler that calls AnalyticsService.track(). If track() throws, it becomes an unhandled error in the finish event. Risk is low (track guards with if (!client) return) but not zero.
What
- Wrap the
res.on('finish') body in try/catch (same pattern as audit middleware .catch(() => {}))
- Add unit test for the error path
Acceptance
Context
The analytics auto-capture middleware registers a
res.on('finish')handler that callsAnalyticsService.track(). If track() throws, it becomes an unhandled error in the finish event. Risk is low (track guards withif (!client) return) but not zero.What
res.on('finish')body in try/catch (same pattern as audit middleware.catch(() => {}))Acceptance