errorBoundary(errorHandler, ...middleware) {
        const composer = new Composer(...middleware);
        const bound = flatten(composer);
        this.use(async (ctx, next) => {
            let nextCalled = false;
            const cont = () => ((nextCalled = true), Promise.resolve());
            try {
                await bound(ctx, cont);
            }
            catch (err) {
                nextCalled = false;
                await errorHandler(new BotError(err, ctx), cont);
            }
            if (nextCalled)
                await next();
        });
        return composer;
    }
/**
     * > This is an advanced function of grammY.
     *
     * Installs an error boundary that catches errors that happen only inside
     * the given middleware. This allows you to install custom error handlers
     * that protect some parts of your bot. Errors will not be able to bubble
     * out of this part of your middleware system, unless the supplied error
     * handler rethrows them, in which case the next surrounding error boundary
     * will catch the error.
     *
     * Example usage:
     * ```ts
     * function errHandler(err: BotError) {
     *   console.error('Error boundary caught error!', err)
     * }
     *
     * const safe =
     *   // All passed middleware will be protected by the error boundary.
     *   bot.errorBoundary(errHandler, middleware0, middleware1, middleware2)
     *
     * // Those will also be protected!
     * safe.on('message', middleware3)
     *
     * // No error from `middleware4` will reach the `errHandler` from above,
     * // as errors are suppressed.
     *
     * // do nothing on error (suppress error), and run outside middleware
     * const suppress = (_err: BotError, next: NextFunction) => { return next() }
     * safe.errorBoundary(suppress).on('edited_message', middleware4)
     * ```
     *
     * Check out the
     * [documentation](https://grammy.dev/guide/errors.html#error-boundaries) on
     * the website to learn more about error boundaries.
     *
     * @param errorHandler The error handler to use
     * @param middleware The middleware to protect
     */
> This is an advanced function of grammY.
Installs an error boundary that catches errors that happen only inside
the given middleware. This allows you to install custom error handlers
that protect some parts of your bot. Errors will not be able to bubble
out of this part of your middleware system, unless the supplied error
handler rethrows them, in which case the next surrounding error boundary
will catch the error.

Example usage:
```ts
function errHandler(err: BotError) {
console.error('Error boundary caught error!', err)
}

const safe
All passed middleware will be protected by the error boundary.

Those will also be protected.

No error from `middleware4` will reach the `errHandler` from above,
as errors are suppressed.

do nothing on error (suppress error), and run outside middleware
const suppress = (_err: BotError, next: NextFunction) => { return next() }
safe.errorBoundary(suppress).on('edited_message', middleware4)
```

Check out the
[documentation] on
the website to learn more about error boundaries.

@param errorHandler The error handler to use
@param middleware The middleware to protect
> This is an advanced function of grammY . Installs an error boundary that catches errors that happen only inside the given middleware . This allows you to install custom error handlers that protect some parts of your bot . Errors will not be able to bubble out of this part of your middleware system unless the supplied error handler rethrows them in which case the next surrounding error boundary will catch the error . Example usage : ` ` ` ts function errHandler ( err : BotError ) { console . error ( ' Error boundary caught error! ' err ) } const safe All passed middleware will be protected by the error boundary . Those will also be protected . No error from ` middleware4 ` will reach the ` errHandler ` from above as errors are suppressed . do nothing on error ( suppress error ) and run outside middleware const suppress = ( _err : BotError next : NextFunction ) = > { return next () } safe . errorBoundary ( suppress ) . on ( ' edited_message ' middleware4 ) ` ` ` Check out the [ documentation ] on the website to learn more about error boundaries . @param errorHandler The error handler to use @param middleware The middleware to protect
errorBoundary(errorHandler, ...middleware) {
        const composer = new Composer(...middleware);
        const bound = flatten(composer);
        this.use(async (ctx, next) => {
            let nextCalled = false;
            const cont = () => ((nextCalled = true), Promise.resolve());
            try {
                await bound(ctx, cont);
            }
            catch (err) {
                nextCalled = false;
                await errorHandler(new BotError(err, ctx), cont);
            }
            if (nextCalled)
                await next();
        });
        return composer;
    }
errorBoundary ( errorHandler , ... middleware ) { const composer = new Composer ( ... middleware ) ; const bound = flatten ( composer ) ; this . use ( async ( ctx , next ) => { let nextCalled = false ; const cont = ( ) => ( ( nextCalled = true ) , Promise . resolve ( ) ) ; try { await bound ( ctx , cont ) ; } catch ( err ) { nextCalled = false ; await errorHandler ( new BotError ( err , ctx ) , cont ) ; } if ( nextCalled ) await next ( ) ; } ) ; return composer ; }
> This is an advanced function of grammY.
> This is an advanced function of grammY .