Answer 502 for an upstream host with no address or a failed fetch (closes #367)
check / check (push) Canceled after 0s

The image routes answered 500 and logged at error level when the upstream
host had no address, or when the fetch failed before the upstream
answered, such as on a refused connection. The fetcher now marks such a
failure with ErrUpstreamRequestFailed; a cancelled fetch is not marked.
respondImageError answers it, and ErrInvalidHost, 502 "upstream error"
and logs them at warn level. README Routes lists both under 502.

Model: opus-5-5
This commit is contained in:
clawbot committed 2026-11-11 21:13:39 +00:00
1 parent 0de6972c2d
commit 67205eb7a9
5 files changed
+101 -5

No files matched your search

@@ -12,6 +12,7 @@ import (
"net/http/httptest"
"slices"
"strings"
"syscall"
"testing"
"testing/fstest"
"time"
@@ -461,6 +462,13 @@ func TestImageRoutes_SameErrorAnswers(t *testing.T) {
{"upstream error status",
fmt.Errorf("%w: status 404", httpfetcher.ErrUpstreamError),
http.StatusBadGateway, slog.LevelWarn},
{"upstream host with no address",
fmt.Errorf("%w: cdn.example.com", httpfetcher.ErrInvalidHost),
http.StatusBadGateway, slog.LevelWarn},
{"connection refused",
fmt.Errorf("%w: %w", httpfetcher.ErrUpstreamRequestFailed,
syscall.ECONNREFUSED),
http.StatusBadGateway, slog.LevelWarn},
{"no response headers within the fetch timeout",
httpfetcher.ErrUpstreamTimeout, http.StatusGatewayTimeout,
slog.LevelWarn},