Class HttpException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BadRequestException, ForbiddenException, InternalServerException, NotFoundException, UnauthorizedException

public class HttpException extends RuntimeException
Runtime exception for applications.

This exception may be thrown during request processing if a specific HTTP error response needs to be produced. Only effective if thrown before the status code is sent.

See Also:
  • Constructor Details

    • HttpException

      public HttpException(String message)
      Parameters:
      message - the message
    • HttpException

      public HttpException(String message, Throwable cause)
      Parameters:
      message - the message
      cause - the cause of this exception
    • HttpException

      public HttpException(String message, Status status)
      Creates HttpException.
      Parameters:
      message - the message
      status - the http status
    • HttpException

      public HttpException(String message, Status status, boolean keepAlive)
      Creates HttpException.
      Parameters:
      message - the message
      status - the http status
      keepAlive - whether to keep the connection alive
    • HttpException

      public HttpException(String message, Status status, Throwable cause)
      Creates HttpException.
      Parameters:
      message - the message
      status - the http status
      cause - the cause of this exception
    • HttpException

      public HttpException(String message, Status status, Throwable cause, boolean keepAlive)
      Creates HttpException.
      Parameters:
      message - the message
      status - the http status
      cause - the cause of this exception
      keepAlive - whether to keep this connection alive
  • Method Details

    • status

      public final Status status()
      Obtain the associated http status.
      Returns:
      the http status
    • keepAlive

      public boolean keepAlive()
      Whether we should attempt to keep the connection alive (if enabled for it). Some exceptions may allow the connection to be further used (such as NotFoundException.
      Returns:
      whether to keep alive
    • header

      public HttpException header(Header header)
      Set a response header that should be used if this exception is not handled.
      Parameters:
      header - header to set
      Returns:
      updated instance
    • headers

      public Headers headers()
      Headers as currently configured in this exception.
      Returns:
      headers configured for this exception