error.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package h2mux
  2. import (
  3. "fmt"
  4. "golang.org/x/net/http2"
  5. )
  6. var (
  7. // HTTP2 error codes: https://http2.github.io/http2-spec/#ErrorCodes
  8. ErrHandshakeTimeout = MuxerHandshakeError{"1000 handshake timeout"}
  9. ErrBadHandshakeNotSettings = MuxerHandshakeError{"1001 unexpected response"}
  10. ErrBadHandshakeUnexpectedAck = MuxerHandshakeError{"1002 unexpected response"}
  11. ErrBadHandshakeNoMagic = MuxerHandshakeError{"1003 unexpected response"}
  12. ErrBadHandshakeWrongMagic = MuxerHandshakeError{"1004 connected to endpoint of wrong type"}
  13. ErrBadHandshakeNotSettingsAck = MuxerHandshakeError{"1005 unexpected response"}
  14. ErrBadHandshakeUnexpectedSettings = MuxerHandshakeError{"1006 unexpected response"}
  15. ErrUnexpectedFrameType = MuxerProtocolError{"2001 unexpected frame type", http2.ErrCodeProtocol}
  16. ErrUnknownStream = MuxerProtocolError{"2002 unknown stream", http2.ErrCodeProtocol}
  17. ErrInvalidStream = MuxerProtocolError{"2003 invalid stream", http2.ErrCodeProtocol}
  18. ErrStreamHeadersSent = MuxerApplicationError{"3000 headers already sent"}
  19. ErrStreamRequestConnectionClosed = MuxerApplicationError{"3001 connection closed while opening stream"}
  20. ErrConnectionDropped = MuxerApplicationError{"3002 connection dropped"}
  21. ErrStreamRequestTimeout = MuxerApplicationError{"3003 open stream timeout"}
  22. ErrResponseHeadersTimeout = MuxerApplicationError{"3004 timeout waiting for initial response headers"}
  23. ErrResponseHeadersConnectionClosed = MuxerApplicationError{"3005 connection closed while waiting for initial response headers"}
  24. ErrClosedStream = MuxerStreamError{"4000 stream closed", http2.ErrCodeStreamClosed}
  25. )
  26. type MuxerHandshakeError struct {
  27. cause string
  28. }
  29. func (e MuxerHandshakeError) Error() string {
  30. return fmt.Sprintf("Handshake error: %s", e.cause)
  31. }
  32. type MuxerProtocolError struct {
  33. cause string
  34. h2code http2.ErrCode
  35. }
  36. func (e MuxerProtocolError) Error() string {
  37. return fmt.Sprintf("Protocol error: %s", e.cause)
  38. }
  39. type MuxerApplicationError struct {
  40. cause string
  41. }
  42. func (e MuxerApplicationError) Error() string {
  43. return fmt.Sprintf("Application error: %s", e.cause)
  44. }
  45. type MuxerStreamError struct {
  46. cause string
  47. h2code http2.ErrCode
  48. }
  49. func (e MuxerStreamError) Error() string {
  50. return fmt.Sprintf("Stream error: %s", e.cause)
  51. }