From 2220371efd0f3846ba1d32a57ba97cb3ab24f168 Mon Sep 17 00:00:00 2001 From: teidesu <86301490+teidesu@users.noreply.github.com> Date: Sun, 27 Jun 2021 23:59:04 +0300 Subject: [PATCH] feat(dispatcher): conditional error propagation to client --- packages/dispatcher/src/dispatcher.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/dispatcher/src/dispatcher.ts b/packages/dispatcher/src/dispatcher.ts index 9223fed9..6b3406f1 100644 --- a/packages/dispatcher/src/dispatcher.ts +++ b/packages/dispatcher/src/dispatcher.ts @@ -38,7 +38,7 @@ import { UserStatusUpdate } from './updates/user-status-update' import { UserTypingUpdate } from './updates/user-typing-update' import { DeleteMessageUpdate } from './updates/delete-message-update' import { IStateStorage, UpdateState, StateKeyDelegate } from './state' -import { defaultStateKeyDelegate } from './state/key' +import { defaultStateKeyDelegate } from './state' import { PropagationAction } from './propagation' const noop = () => {} @@ -171,7 +171,7 @@ export class Dispatcher { err: Error, update: UpdateInfoForError, state?: UpdateState - ) => MaybeAsync + ) => MaybeAsync /** * Create a new dispatcher, that will be used as a child, @@ -491,11 +491,12 @@ export class Dispatcher { } } catch (e) { if (this._errorHandler) { - await this._errorHandler( + const handled = await this._errorHandler( e, { type: parsedType, data: parsed }, parsedState as never ) + if (!handled) throw e } else { throw e } @@ -616,7 +617,7 @@ export class Dispatcher { err: Error, update: UpdateInfoForError, state?: UpdateState - ) => MaybeAsync) + ) => MaybeAsync) | null ): void { if (handler) this._errorHandler = handler @@ -631,7 +632,7 @@ export class Dispatcher { err: Error, update: UpdateInfoForError, state?: UpdateState - ): MaybeAsync { + ): MaybeAsync { if (!this.parent) throw new MtCuteArgumentError('This dispatcher is not a child')