Repository navigation
Expand file tree
/
Copy patherror.go
More file actions
56 lines (49 loc) · 1.58 KB
/
Copy patherror.go
File metadata and controls
56 lines (49 loc) · 1.58 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
package httpproxy
import (
"errors"
)
var (
ErrPreRoundTrip = errors.New("pre round-trip hook failed")
ErrPostRoundTrip = errors.New("post round-trip hook failed")
ErrClientCanceled = errors.New("client canceled request")
ErrRoundTrip = errors.New("round-trip failed")
ErrWriteResponse = errors.New("writing response to client failed")
ErrFlushResponse = errors.New("flushing response to client failed")
ErrProtocolMismatch = errors.New("protocol switch: protocols mismatch")
ErrNonSwitchable = errors.New("protocol switch: unable to switch protocol")
ErrBidirectionalCom = errors.New("protocol switch: bidirectional communication failed")
)
// Error is the proxy error.
type Error struct {
Inner error // Inner is the inner error.
Cause error // Cause is the error cause in the proxy.
Detail string // Detail is the error detail.
// written indicates that the response has already written.
// Any error response must not be written to response writer.
written bool
}
// Writable reports if an error response is writable to the ResponseWriter.
// Do not write status code or bodies to ResponseWriter in error handler when false.
func (e *Error) Writable() bool {
return !e.written
}
func (e *Error) Unwrap() error {
return e.Inner
}
func (e *Error) Error() string {
s := "go-httpproxy/httpproxy: " + e.Cause.Error()
if e.Detail != "" {
s += ". " + e.Detail
}
if e.Inner != nil {
s = s + " [" + e.Inner.Error() + "]"
}
return s
}
func (e *Error) Is(target error) bool {
ee, ok := target.(*Error)
if ok {
return e.Cause == ee.Cause
}
return false
}