fix: client-cancelled GET /v0/servers returns 499 without error log (#1335)
Maps context.Canceled from ListServers to 499 and skips the error-level log on client disconnect. Merged as-is per maintainer decision; known follow-up tracked in #1337 (500-path error-detail leak + WriteHeader claim correction + nits).
This commit is contained in:
parent
04623ed925
commit
ef29673221
1 changed files with 53 additions and 2 deletions
21
internal/api/handlers/v0/list_errors.go
Normal file
21
internal/api/handlers/v0/list_errors.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package v0
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"github.com/danielgtaylor/huma/v2"
|
||||
)
|
||||
|
||||
// ListServersError maps ListServers failures; client disconnects must not log as 500s.
|
||||
func ListServersError(ctx context.Context, err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if errors.Is(err, context.Canceled) || errors.Is(ctx.Err(), context.Canceled) {
|
||||
return huma.NewError(499, "Client closed request", err)
|
||||
}
|
||||
log.Printf("list servers failed: %v", err)
|
||||
return huma.Error500InternalServerError("Failed to get registry list", err)
|
||||
}
|
||||
Loading…
Reference in a new issue