Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

analytics-node might cause an unhandledRejection #320

@yigaldviri

Description

@yigaldviri

Hi there,

Im trying to use this package to report events to Segment and as a consumer I'm trying to protect my server from errors. My code looks like this:

track = promisify(analytics.track.bind(analytics));

async report (userId: string, eventType: SegmentEvent, properties) {
    try {
      await track({
        userId,
        event: eventType,
        properties: addLinkToProperties(eventType, properties),
      });
    }
    catch (e) {
      log.warn('Couldn\'t report to segment about event', { eventType, properties, e });
    }
  }

I had a look at the package's code and I think that In some cases the package can cause an unhandledRejection error. For examplee, in case of a downtime on Segment servers.

I simulated it by changing the code and throwing an error inside the then clause of the flush function:
image

Tested it an indeed I got [ERROR] - unhandledRejection: Error: test an error

This kind of error might result in a server crush and using try/catch wont help either so am I missing here something? Is there a way to avoid that error? Or maybe my case can't really happen in reality?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions