Skip to content

fix(analytics): add try/catch in middleware finish handler #3321

@PierreBrisorgueil

Description

@PierreBrisorgueil

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

  • Analytics middleware finish handler catches exceptions
  • Test verifies no unhandled error when track() throws

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions