errors.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2014 The Go Authors.
  2. // See https://code.google.com/p/go/source/browse/CONTRIBUTORS
  3. // Licensed under the same terms as Go itself:
  4. // https://code.google.com/p/go/source/browse/LICENSE
  5. package http2
  6. import "fmt"
  7. // An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec.
  8. type ErrCode uint32
  9. const (
  10. ErrCodeNo ErrCode = 0x0
  11. ErrCodeProtocol ErrCode = 0x1
  12. ErrCodeInternal ErrCode = 0x2
  13. ErrCodeFlowControl ErrCode = 0x3
  14. ErrCodeSettingsTimeout ErrCode = 0x4
  15. ErrCodeStreamClosed ErrCode = 0x5
  16. ErrCodeFrameSize ErrCode = 0x6
  17. ErrCodeRefusedStream ErrCode = 0x7
  18. ErrCodeCancel ErrCode = 0x8
  19. ErrCodeCompression ErrCode = 0x9
  20. ErrCodeConnect ErrCode = 0xa
  21. ErrCodeEnhanceYourCalm ErrCode = 0xb
  22. ErrCodeInadequateSecurity ErrCode = 0xc
  23. ErrCodeHTTP11Required ErrCode = 0xd
  24. )
  25. var errCodeName = map[ErrCode]string{
  26. ErrCodeNo: "NO_ERROR",
  27. ErrCodeProtocol: "PROTOCOL_ERROR",
  28. ErrCodeInternal: "INTERNAL_ERROR",
  29. ErrCodeFlowControl: "FLOW_CONTROL_ERROR",
  30. ErrCodeSettingsTimeout: "SETTINGS_TIMEOUT",
  31. ErrCodeStreamClosed: "STREAM_CLOSED",
  32. ErrCodeFrameSize: "FRAME_SIZE_ERROR",
  33. ErrCodeRefusedStream: "REFUSED_STREAM",
  34. ErrCodeCancel: "CANCEL",
  35. ErrCodeCompression: "COMPRESSION_ERROR",
  36. ErrCodeConnect: "CONNECT_ERROR",
  37. ErrCodeEnhanceYourCalm: "ENHANCE_YOUR_CALM",
  38. ErrCodeInadequateSecurity: "INADEQUATE_SECURITY",
  39. ErrCodeHTTP11Required: "HTTP_1_1_REQUIRED",
  40. }
  41. func (e ErrCode) String() string {
  42. if s, ok := errCodeName[e]; ok {
  43. return s
  44. }
  45. return fmt.Sprintf("unknown error code 0x%x", uint32(e))
  46. }
  47. // ConnectionError is an error that results in the termination of the
  48. // entire connection.
  49. type ConnectionError ErrCode
  50. func (e ConnectionError) Error() string { return fmt.Sprintf("connection error: %s", ErrCode(e)) }
  51. // StreamError is an error that only affects one stream within an
  52. // HTTP/2 connection.
  53. type StreamError struct {
  54. StreamID uint32
  55. Code ErrCode
  56. }
  57. func (e StreamError) Error() string {
  58. return fmt.Sprintf("stream error: stream ID %d; %v", e.StreamID, e.Code)
  59. }
  60. // 6.9.1 The Flow Control Window
  61. // "If a sender receives a WINDOW_UPDATE that causes a flow control
  62. // window to exceed this maximum it MUST terminate either the stream
  63. // or the connection, as appropriate. For streams, [...]; for the
  64. // connection, a GOAWAY frame with a FLOW_CONTROL_ERROR code."
  65. type goAwayFlowError struct{}
  66. func (goAwayFlowError) Error() string { return "connection exceeded flow control window size" }