From 0a89b2005c2c1a8e350fd0d15f29ab59d35c3bda Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Thu, 2 Jul 2026 20:18:23 +1000 Subject: [PATCH] fix: isNetworkError should use errors.As, not a bare type assertion (#84) Fixes #68 ## Why `isNetworkError` type-asserted `err.(*UpstreamError)` directly. If the error is ever wrapped, stale-on-error handling silently stops triggering. ## Changes - Use `errors.As` to detect `*UpstreamError` through wrapping. ## Validation - `make e2e` passes. Reviewed-on: https://git.unkin.net/unkin/artifactapi/pulls/84 Co-authored-by: Ben Vincent Co-committed-by: Ben Vincent --- internal/proxy/engine.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/proxy/engine.go b/internal/proxy/engine.go index c7dbc72..94d0fca 100644 --- a/internal/proxy/engine.go +++ b/internal/proxy/engine.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" + "errors" "fmt" "io" "log/slog" @@ -422,8 +423,6 @@ func (e *UpstreamError) Error() string { return fmt.Sprintf("upstream error: %v" func (e *UpstreamError) Unwrap() error { return e.Err } func isNetworkError(err error) bool { - if _, ok := err.(*UpstreamError); ok { - return true - } - return false + var ue *UpstreamError + return errors.As(err, &ue) }