errors.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package http2
  2. import "fmt"
  3. type ErrCode uint32
  4. const (
  5. ErrCodeNo ErrCode = 0x0
  6. ErrCodeProtocol ErrCode = 0x1
  7. ErrCodeInternal ErrCode = 0x2
  8. ErrCodeFlowControl ErrCode = 0x3
  9. ErrCodeSettingsTimeout ErrCode = 0x4
  10. ErrCodeStreamClosed ErrCode = 0x5
  11. ErrCodeFrameSize ErrCode = 0x6
  12. ErrCodeRefusedStream ErrCode = 0x7
  13. ErrCodeCancel ErrCode = 0x8
  14. ErrCodeCompression ErrCode = 0x9
  15. ErrCodeConnect ErrCode = 0xa
  16. ErrCodeEnhanceYourCalm ErrCode = 0xb
  17. ErrCodeInadequateSecurity ErrCode = 0xc
  18. )
  19. var ErrCodeName = map[ErrCode]string{
  20. ErrCodeNo: "NO_ERROR",
  21. ErrCodeProtocol: "PROTOCOL_ERROR",
  22. ErrCodeInternal: "INTERNAL_ERROR",
  23. ErrCodeFlowControl: "FLOW_CONTROL_ERROR",
  24. ErrCodeSettingsTimeout: "SETTINGS_TIMEOUT",
  25. ErrCodeStreamClosed: "STREAM_CLOSED",
  26. ErrCodeFrameSize: "FRAME_SIZE_ERROR",
  27. ErrCodeRefusedStream: "REFUSED_STREAM",
  28. ErrCodeCancel: "CANCEL",
  29. ErrCodeCompression: "COMPRESSION_ERROR",
  30. ErrCodeConnect: "CONNECT_ERROR",
  31. ErrCodeEnhanceYourCalm: "ENHANCE_YOUR_CALM",
  32. ErrCodeInadequateSecurity: "INADEQUATE_SECURITY",
  33. }
  34. func (e ErrCode) String() string {
  35. if s, ok := ErrCodeName[e]; ok {
  36. return s
  37. }
  38. return fmt.Sprintf("unknown error code %x", e)
  39. }
  40. type Error interface {
  41. IsStreamError() bool
  42. IsConnectionError() bool
  43. error
  44. }
  45. type ConnectionError ErrCode
  46. var _ Error = ConnectionError(0)
  47. func (e ConnectionError) IsStreamError() bool { return false }
  48. func (e ConnectionError) IsConnectionError() bool { return true }
  49. func (e ConnectionError) Error() string { return fmt.Sprintf("connection error: %s", ErrCode(e)) }