error.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. ErrNotRPCStream = MuxerProtocolError{"2004 not RPC stream", http2.ErrCodeProtocol}
  19. ErrStreamHeadersSent = MuxerApplicationError{"3000 headers already sent"}
  20. ErrStreamRequestConnectionClosed = MuxerApplicationError{"3001 connection closed while opening stream"}
  21. ErrConnectionDropped = MuxerApplicationError{"3002 connection dropped"}
  22. ErrStreamRequestTimeout = MuxerApplicationError{"3003 open stream timeout"}
  23. ErrResponseHeadersTimeout = MuxerApplicationError{"3004 timeout waiting for initial response headers"}
  24. ErrResponseHeadersConnectionClosed = MuxerApplicationError{"3005 connection closed while waiting for initial response headers"}
  25. ErrClosedStream = MuxerStreamError{"4000 stream closed", http2.ErrCodeStreamClosed}
  26. )
  27. type MuxerHandshakeError struct {
  28. cause string
  29. }
  30. func (e MuxerHandshakeError) Error() string {
  31. return fmt.Sprintf("Handshake error: %s", e.cause)
  32. }
  33. type MuxerProtocolError struct {
  34. cause string
  35. h2code http2.ErrCode
  36. }
  37. func (e MuxerProtocolError) Error() string {
  38. return fmt.Sprintf("Protocol error: %s", e.cause)
  39. }
  40. type MuxerApplicationError struct {
  41. cause string
  42. }
  43. func (e MuxerApplicationError) Error() string {
  44. return fmt.Sprintf("Application error: %s", e.cause)
  45. }
  46. type MuxerStreamError struct {
  47. cause string
  48. h2code http2.ErrCode
  49. }
  50. func (e MuxerStreamError) Error() string {
  51. return fmt.Sprintf("Stream error: %s", e.cause)
  52. }