errors.go 2.2 KB

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