Class Http2Exception

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
HeaderListSizeException

public class Http2Exception extends IOException
A violation of HTTP/2 or HPACK by the peer (or a limit it exceeded), with the error code to send back and the scope of the error (RFC 9113 §5.4).
  • A connection error (isConnectionError()) leaves the connection unusable: send GOAWAY with errorCode() and close it. The reader that threw it must not be used again.
  • A stream error affects only streamId(): send RST_STREAM with errorCode() and carry on. When a FrameReader throws one it has consumed the whole offending frame, so reading can continue.

Any stream error may be treated as a connection error by a caller that prefers to.

See Also:
  • Constructor Details

    • Http2Exception

      protected Http2Exception(ErrorCode errorCode, int streamId, boolean connectionError, String message)
      Creates an error with an explicit protocol scope.
      Parameters:
      errorCode - the non-null code to report to the peer
      streamId - the affected stream identifier, or 0 for the connection
      connectionError - whether the entire connection is unusable
      message - the diagnostic message
  • Method Details

    • connectionError

      public static Http2Exception connectionError(ErrorCode errorCode, String message)
      An error that ends the connection.
      Parameters:
      errorCode - the non-null code to report to the peer
      message - the diagnostic message
      Returns:
      a connection-scoped exception
    • streamError

      public static Http2Exception streamError(int streamId, ErrorCode errorCode, String message)
      An error that ends only the given stream.
      Parameters:
      streamId - the positive identifier of the affected stream
      errorCode - the non-null code to report to the peer
      message - the diagnostic message
      Returns:
      a stream-scoped exception
    • errorCode

      public ErrorCode errorCode()
      The code to send in GOAWAY (connection error) or RST_STREAM (stream error).
      Returns:
      the code to report to the peer
    • streamId

      public int streamId()
      The stream in error, or 0 for a connection error.
      Returns:
      the affected stream identifier, or 0 for a connection error
    • isConnectionError

      public boolean isConnectionError()
      Reports whether the connection must be closed.
      Returns:
      true for a connection error, false for a stream error
    • getMessage

      public String getMessage()
      Overrides:
      getMessage in class Throwable