fix(core): onError doesn't register

This commit is contained in:
alina 🌸 2024-05-19 20:02:40 +03:00
parent cf97a88b0e
commit dc99a9103b
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -238,7 +238,7 @@ export class MtClient extends EventEmitter {
readonly _config = new ConfigManager(() => this.call({ _: 'help.getConfig' })) readonly _config = new ConfigManager(() => this.call({ _: 'help.getConfig' }))
emitError: (err: unknown, connection?: SessionConnection) => void = console.error.bind(console) private _emitError?: (err: unknown, connection?: SessionConnection) => void
readonly log: Logger readonly log: Logger
readonly network: NetworkManager readonly network: NetworkManager
@ -310,6 +310,14 @@ export class MtClient extends EventEmitter {
) )
} }
emitError(err: unknown, connection?: SessionConnection): void {
if (this._emitError) {
this._emitError(err, connection)
} else {
this.log.error('unhandled error:', err)
}
}
private _prepare = asyncResettable(async () => { private _prepare = asyncResettable(async () => {
await this.crypto.initialize?.() await this.crypto.initialize?.()
await this.storage.load() await this.storage.load()