30 lines
589 B
Go
30 lines
589 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/go-telegram/bot"
|
|
"github.com/go-telegram/bot/models"
|
|
"github.com/pkg/errors"
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
type MiddlewareHandler func(next bot.HandlerFunc) bot.HandlerFunc
|
|
|
|
func Recoverer(next bot.HandlerFunc) bot.HandlerFunc {
|
|
return func(ctx context.Context, bot *bot.Bot, update *models.Update){
|
|
defer func() {
|
|
panic := recover()
|
|
if panic != nil {
|
|
zerolog.Ctx(ctx).Error().
|
|
Stack().
|
|
Err(errors.WithStack(fmt.Errorf("%v", panic))).
|
|
Msg("Panic recovered")
|
|
}
|
|
}()
|
|
|
|
next(ctx, bot, update)
|
|
}
|
|
}
|