2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-06-24 15:33:42 +08:00

servemux: NotFoundHandler returns ErrHandlerNotFound error

This allows asynq middlewares to be used to inspect returned errors and decide
to silence errors about `handlers not found for task'.
This commit is contained in:
Marin Atanasov Nikolov 2025-03-07 12:58:08 +02:00
parent 489e21920b
commit 0eead6348a

View File

@ -6,12 +6,16 @@ package asynq
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"sort" "sort"
"strings" "strings"
"sync" "sync"
) )
// ErrHandlerNotFound indicates that no task handler was found for a given pattern.
var ErrHandlerNotFound = errors.New("handler not found for task")
// ServeMux is a multiplexer for asynchronous tasks. // ServeMux is a multiplexer for asynchronous tasks.
// It matches the type of each task against a list of registered patterns // It matches the type of each task against a list of registered patterns
// and calls the handler for the pattern that most closely matches the // and calls the handler for the pattern that most closely matches the
@ -149,7 +153,7 @@ func (mux *ServeMux) Use(mws ...MiddlewareFunc) {
// NotFound returns an error indicating that the handler was not found for the given task. // NotFound returns an error indicating that the handler was not found for the given task.
func NotFound(ctx context.Context, task *Task) error { func NotFound(ctx context.Context, task *Task) error {
return fmt.Errorf("handler not found for task %q", task.Type()) return fmt.Errorf("%w %q", ErrHandlerNotFound, task.Type())
} }
// NotFoundHandler returns a simple task handler that returns a ``not found`` error. // NotFoundHandler returns a simple task handler that returns a ``not found`` error.