-
Notifications
You must be signed in to change notification settings - Fork 36
/
errors.go
80 lines (70 loc) · 2.04 KB
/
errors.go
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
package http2
import (
"fmt"
)
// ErrorCode defines the HTTP/2 error codes:
//
// Error codes are defined here http://httpwg.org/specs/rfc7540.html#ErrorCodes
//
// Errors must be uint32 because of FrameReset
type ErrorCode uint32
const (
NoError ErrorCode = 0x0
ProtocolError = 0x1
InternalError = 0x2
FlowControlError = 0x3
SettingsTimeoutError = 0x4
StreamClosedError = 0x5
FrameSizeError = 0x6
RefusedStreamError = 0x7
CancelError = 0x8
CompressionError = 0x9
ConnectionError = 0xa
EnhanceYourCalm = 0xb
InadequateSecurity = 0xc
HTTP11Required = 0xd
)
func (e ErrorCode) Error() string {
return errParser[e]
}
type Error struct {
code ErrorCode
debug string
}
func (e Error) Code() ErrorCode {
return e.code
}
func NewError(e ErrorCode, debug string) Error {
return Error{
code: e,
debug: debug,
}
}
func (e Error) Error() string {
return fmt.Sprintf("%s: %s", e.code, e.debug)
}
var (
errParser = []string{
NoError: "No errors",
ProtocolError: "Protocol error",
InternalError: "Internal error",
FlowControlError: "Flow control error",
SettingsTimeoutError: "Settings timeout",
StreamClosedError: "Stream have been closed",
FrameSizeError: "FrameHeader size error",
RefusedStreamError: "Refused Stream",
CancelError: "Canceled",
CompressionError: "Compression error",
ConnectionError: "Connection error",
EnhanceYourCalm: "Enhance your calm",
InadequateSecurity: "Inadequate security",
HTTP11Required: "HTTP/1.1 required",
}
// This error codes must be used with FrameGoAway
ErrUnknowFrameType = NewError(
ProtocolError, "unknown frame type")
ErrMissingBytes = NewError(
ProtocolError, "missing payload bytes. Need more")
ErrPayloadExceeds = NewError(
ProtocolError, "FrameHeader payload exceeds the negotiated maximum size")
)