fix: Add "connection dead" to internalErrors list

This commit is contained in:
divyam234 2024-03-26 10:54:31 +05:30
parent e31147aa72
commit 8fe47ba256

View file

@ -18,6 +18,7 @@ var internalErrors = []string{
"RPC_MCGET_FAIL",
"WORKER_BUSY_TOO_LONG_RETRY",
"memory limit exit",
"connection dead",
}
type retry struct {
@ -25,13 +26,22 @@ type retry struct {
errors []string
}
func isErrorMatch(err error) bool {
for _, internalError := range internalErrors {
if errors.Is(err, errors.New(internalError)) {
return true
}
}
return false
}
func (r retry) Handle(next tg.Invoker) telegram.InvokeFunc {
return func(ctx context.Context, input bin.Encoder, output bin.Decoder) error {
retries := 0
for retries < r.max {
if err := next.Invoke(ctx, input, output); err != nil {
if tgerr.Is(err, r.errors...) {
if tgerr.Is(err, r.errors...) || isErrorMatch(err) {
retries++
continue
}