Unwrap errors in normalizeTimeoutError

pull/1837/head
Samuel Stauffer 2023-12-13 17:44:10 -08:00 committed by Jack Christensen
parent 2daeb8dc5f
commit 9ab9e3c40b
1 changed files with 3 additions and 2 deletions

View File

@ -107,14 +107,15 @@ func (e *parseConfigError) Unwrap() error {
} }
func normalizeTimeoutError(ctx context.Context, err error) error { func normalizeTimeoutError(ctx context.Context, err error) error {
if err, ok := err.(net.Error); ok && err.Timeout() { var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
if ctx.Err() == context.Canceled { if ctx.Err() == context.Canceled {
// Since the timeout was caused by a context cancellation, the actual error is context.Canceled not the timeout error. // Since the timeout was caused by a context cancellation, the actual error is context.Canceled not the timeout error.
return context.Canceled return context.Canceled
} else if ctx.Err() == context.DeadlineExceeded { } else if ctx.Err() == context.DeadlineExceeded {
return &errTimeout{err: ctx.Err()} return &errTimeout{err: ctx.Err()}
} else { } else {
return &errTimeout{err: err} return &errTimeout{err: netErr}
} }
} }
return err return err