fix: avoid emitting version warning when connection error encountered (#3082)

This commit is contained in:
Jon Ayers
2022-07-21 14:28:24 -05:00
committed by GitHub
parent 5b78251592
commit e01905821f
4 changed files with 91 additions and 2 deletions

View File

@ -1,5 +1,11 @@
package codersdk
import (
"net"
"golang.org/x/xerrors"
)
// Response represents a generic HTTP response.
type Response struct {
// Message is an actionable message that depicts actions the request took.
@ -25,3 +31,16 @@ type ValidationError struct {
Field string `json:"field" validate:"required"`
Detail string `json:"detail" validate:"required"`
}
// IsConnectionErr is a convenience function for checking if the source of an
// error is due to a 'connection refused', 'no such host', etc.
func IsConnectionErr(err error) bool {
var (
// E.g. no such host
dnsErr *net.DNSError
// Eg. connection refused
opErr *net.OpError
)
return xerrors.As(err, &dnsErr) || xerrors.As(err, &opErr)
}