-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy patherrors.go
More file actions
51 lines (40 loc) · 1.86 KB
/
Copy patherrors.go
File metadata and controls
51 lines (40 loc) · 1.86 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
package surf
import "fmt"
// Custom error types for surf HTTP client operations.
// These errors provide specific information about different failure scenarios
// that can occur during HTTP requests and responses.
type (
// ErrWebSocketUpgrade indicates that a request received a WebSocket upgrade response.
// This error is returned when the server responds with HTTP 101 Switching Protocols
// for WebSocket connections, which require special handling.
ErrWebSocketUpgrade struct{ Msg string }
// ErrUserAgentType indicates an invalid user agent type was provided.
// This error is returned when the user agent parameter is not of a supported type
// (string, g.String, slices, etc.).
ErrUserAgentType struct{ Msg string }
// Err101ResponseCode indicates a 101 Switching Protocols response was received.
// This error is used to handle HTTP 101 responses that require protocol upgrades.
Err101ResponseCode struct{ Msg string }
// ErrHTTP2Fallback indicates that an HTTPS request attempted HTTP/2 first,
// then tried to fall back to HTTP/1.1, but both attempts failed.
//
// Both underlying errors are accessible via Unwrap, enabling
// errors.Is and errors.As to match against either the HTTP/2 or HTTP/1.1 failure.
ErrHTTP2Fallback struct {
HTTP2 error
HTTP1 error
}
)
func (e *ErrWebSocketUpgrade) Error() string {
return fmt.Sprintf("%s received an unexpected response, switching protocols to WebSocket", e.Msg)
}
func (e *ErrUserAgentType) Error() string {
return fmt.Sprintf("unsupported user agent type: %s", e.Msg)
}
func (e *Err101ResponseCode) Error() string {
return fmt.Sprintf("%s received a 101 response status code", e.Msg)
}
func (e *ErrHTTP2Fallback) Error() string {
return fmt.Sprintf("surf: HTTP/2 request failed: %v; HTTP/1.1 fallback failed: %v", e.HTTP2, e.HTTP1)
}
func (e *ErrHTTP2Fallback) Unwrap() []error { return []error{e.HTTP2, e.HTTP1} }