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:
CK 2026-06-05 01:59:47 -05:00 • committed by GitHub
commit ef29673221
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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)
}