Enable lint rules for Promise handling to discourage misuse of them.

Squashed all of Hugh's commits into one.
This commit is contained in:
Hugh Nimmo-Smith
2024-07-10 16:20:59 +01:00
committed by Timo
parent c2cc0937c1
commit 480a995be1
31 changed files with 332 additions and 198 deletions

View File

@@ -265,7 +265,7 @@ export class PosthogAnalytics {
this.posthog.identify(analyticsID);
} else {
logger.info(
"No analyticsID is availble. Should not try to setup posthog",
"No analyticsID is available. Should not try to setup posthog",
);
}
}
@@ -333,7 +333,9 @@ export class PosthogAnalytics {
}
public onLoginStatusChanged(): void {
this.maybeIdentifyUser();
this.maybeIdentifyUser().catch(() =>
logger.log("Could not identify user on login status change"),
);
}
private updateSuperProperties(): void {
@@ -382,20 +384,27 @@ export class PosthogAnalytics {
}
}
public async trackEvent<E extends IPosthogEvent>(
public trackEvent<E extends IPosthogEvent>(
{ eventName, ...properties }: E,
options?: CaptureOptions,
): Promise<void> {
): void {
const doCapture = (): void => {
if (
this.anonymity == Anonymity.Disabled ||
this.anonymity == Anonymity.Anonymous
)
return;
this.capture(eventName, properties, options);
};
if (this.identificationPromise) {
// only make calls to posthog after the identificaion is done
await this.identificationPromise;
// only make calls to posthog after the identification is done
this.identificationPromise.then(doCapture).catch((e) => {
logger.error("Failed to identify user for tracking", e);
});
} else {
doCapture();
}
if (
this.anonymity == Anonymity.Disabled ||
this.anonymity == Anonymity.Anonymous
)
return;
this.capture(eventName, properties, options);
}
private startListeningToSettingsChanges(): void {
@@ -409,7 +418,9 @@ export class PosthogAnalytics {
// won't be called (i.e. this.anonymity will be left as the default, until the setting changes)
optInAnalytics.value.subscribe((optIn) => {
this.setAnonymity(optIn ? Anonymity.Pseudonymous : Anonymity.Disabled);
this.maybeIdentifyUser();
this.maybeIdentifyUser().catch(() =>
logger.log("Could not identify user"),
);
});
}