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: #84 Co-authored-by: Ben Vincent <ben@unkin.net> Co-committed-by: Ben Vincent <ben@unkin.net>
This commit was merged in pull request #84.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user