-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.go
More file actions
83 lines (63 loc) · 3.06 KB
/
errors.go
File metadata and controls
83 lines (63 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package requests
import (
"context"
"errors"
"net"
)
var (
// ErrUnsupportedContentType is returned when the content type is unsupported.
ErrUnsupportedContentType = errors.New("unsupported content type")
// ErrUnsupportedDataType is returned when the data type is unsupported.
ErrUnsupportedDataType = errors.New("unsupported data type")
// ErrEncodingFailed is returned when the encoding fails.
ErrEncodingFailed = errors.New("encoding failed")
// ErrRequestCreationFailed is returned when the request cannot be created.
ErrRequestCreationFailed = errors.New("failed to create request")
// ErrResponseReadFailed is returned when the response cannot be read.
ErrResponseReadFailed = errors.New("failed to read response")
// ErrUnsupportedScheme is returned when the proxy scheme is unsupported.
ErrUnsupportedScheme = errors.New("unsupported proxy scheme")
// ErrNoProxies is returned when no proxy URLs are provided to a rotation function.
ErrNoProxies = errors.New("no proxy URLs provided")
// ErrUnsupportedFormFieldsType is returned when the form fields type is unsupported.
ErrUnsupportedFormFieldsType = errors.New("unsupported form fields type")
// ErrNotSupportSaveMethod is returned when the provided type for saving is not supported.
ErrNotSupportSaveMethod = errors.New("unsupported save type")
// ErrInvalidTransportType is returned when the transport type is invalid.
ErrInvalidTransportType = errors.New("invalid transport type")
// ErrResponseNil is returned when the response is nil.
ErrResponseNil = errors.New("response is nil")
// ErrAutoRedirectDisabled is returned when the auto redirect is disabled.
ErrAutoRedirectDisabled = errors.New("auto redirect disabled")
// ErrTooManyRedirects is returned when the number of redirects is too many.
ErrTooManyRedirects = errors.New("too many redirects")
// ErrRedirectNotAllowed is returned when the redirect is not allowed.
ErrRedirectNotAllowed = errors.New("redirect not allowed")
// ErrTestTimeout is returned when a test request times out (used in tests).
ErrTestTimeout = errors.New("test timeout: request took too long")
// ErrInvalidConfigValue is returned when a config field has an invalid value.
ErrInvalidConfigValue = errors.New("invalid config value")
// ErrInvalidTLSClientCertificateConfig is returned when TLS client cert and key paths are inconsistently configured.
ErrInvalidTLSClientCertificateConfig = errors.New("TLSClientCertFile and TLSClientKeyFile must both be set or both be empty")
)
// IsTimeout reports whether err is or wraps a timeout error.
// It checks for context.DeadlineExceeded and net.Error timeout errors.
func IsTimeout(err error) bool {
if err == nil {
return false
}
if errors.Is(err, context.DeadlineExceeded) {
return true
}
netErr, ok := errors.AsType[net.Error](err)
return ok && netErr.Timeout()
}
// IsConnectionError reports whether err is a connection-level failure
// (DNS resolution, TCP connect, TLS handshake).
func IsConnectionError(err error) bool {
if err == nil {
return false
}
_, ok := errors.AsType[*net.OpError](err)
return ok
}