Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit sync error #366

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ export class MatrixClient extends EventEmitter {
return this.startSync();
}

protected emitAsync(e: string, ...p: any[]): Promise<any> {
return Promise.resolve<any>(this.emit(e, ...p));
}

protected async startSync(emitFn: (emitEventType: string, ...payload: any[]) => Promise<any> = null) {
// noinspection ES6RedundantAwait
let token = await Promise.resolve(this.storage.getSyncToken());
Expand Down Expand Up @@ -728,6 +732,8 @@ export class MatrixClient extends EventEmitter {
}

LogService.error("MatrixClientLite", "Error handling sync " + extractRequestError(e));
await this.emitAsync("sync.error", e);

const backoffTime = SYNC_BACKOFF_MIN_MS + Math.random() * (SYNC_BACKOFF_MAX_MS - SYNC_BACKOFF_MIN_MS);
LogService.info("MatrixClientLite", `Backing off for ${backoffTime}ms`);
await new Promise((r) => setTimeout(r, backoffTime));
Expand Down Expand Up @@ -757,7 +763,7 @@ export class MatrixClient extends EventEmitter {

@timedMatrixClientFunctionCall()
protected async processSync(raw: any, emitFn: (emitEventType: string, ...payload: any[]) => Promise<any> = null): Promise<any> {
if (!emitFn) emitFn = (e, ...p) => Promise.resolve<any>(this.emit(e, ...p));
if (!emitFn) emitFn = (e, ...p) => this.emitAsync(e, ...p);

if (!raw) return; // nothing to process

Expand Down