fix: improve error handling in recovery middleware

This commit is contained in:
krau
2025-08-21 14:39:41 +08:00
parent f0607de2cc
commit 79386bdd7d

View File

@@ -2,11 +2,11 @@ package recovery
import ( import (
"context" "context"
"fmt"
"time" "time"
"github.com/cenkalti/backoff/v4" "github.com/cenkalti/backoff/v4"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
"github.com/go-faster/errors"
"github.com/gotd/td/bin" "github.com/gotd/td/bin"
"github.com/gotd/td/telegram" "github.com/gotd/td/telegram"
"github.com/gotd/td/tg" "github.com/gotd/td/tg"
@@ -31,7 +31,7 @@ func (r *recovery) Handle(next tg.Invoker) telegram.InvokeFunc {
return backoff.RetryNotify(func() error { return backoff.RetryNotify(func() error {
if err := next.Invoke(ctx, input, output); err != nil { if err := next.Invoke(ctx, input, output); err != nil {
if r.shouldRecover(ctx, err) { if r.shouldRecover(ctx, err) {
return errors.Wrap(err, "recover") return fmt.Errorf("recovery: %w", err)
} }
return backoff.Permanent(err) return backoff.Permanent(err)