Class HttpException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BadRequestException, ForbiddenException, InternalServerErrorException, MethodNotAllowedException, NotAcceptableException, NotFoundException, ServiceUnavailableException, UnauthorizedException, UnsupportedMediaTypeException, WebSocketException

public class HttpException extends RuntimeException

Base exception class used to report HTTP errors.

Since:
1.0
Author:
Jeremy Kuhn
See Also:
  • Constructor Details

    • HttpException

      public HttpException()

      Creates an HTTP exception with default status Internal Server Error (500).

    • HttpException

      public HttpException(String message)

      Creates an HTTP exception with default status Internal Server Error (500) and specified message.

      Parameters:
      message - a message
    • HttpException

      public HttpException(Throwable cause)

      Creates an HTTP exception with default status Internal Server Error (500) and specified cause.

      Parameters:
      cause - a cause
    • HttpException

      public HttpException(String message, Throwable cause)

      Creates an HTTP exception with default status Internal Server Error (500), specified message and cause

      Parameters:
      message - a message
      cause - a cause
    • HttpException

      public HttpException(int statusCode) throws IllegalArgumentException

      Creates an HTTP exception with specified HTTP status code.

      Parameters:
      statusCode - an HTTP status code
      Throws:
      IllegalArgumentException - if the specified status code is invalid
    • HttpException

      public HttpException(int statusCode, String message) throws IllegalArgumentException

      Creates an HTTP exception with specified HTTP status code and message.

      Parameters:
      statusCode - an HTTP status code
      message - a message
      Throws:
      IllegalArgumentException - if the specified status code is invalid
    • HttpException

      public HttpException(int statusCode, Throwable cause) throws IllegalArgumentException

      Creates an HTTP exception with specified HTTP status code and cause.

      Parameters:
      statusCode - an HTTP status code
      cause - a cause
      Throws:
      IllegalArgumentException - if the specified status code is invalid
    • HttpException

      public HttpException(int statusCode, String message, Throwable cause) throws IllegalArgumentException

      Creates an HTTP exception with specified HTTP status code, message and cause.

      Parameters:
      statusCode - an HTTP status code
      message - a message
      cause - a cause
      Throws:
      IllegalArgumentException - if the specified status code is invalid
    • HttpException

      public HttpException(Status status)

      Creates an HTTP exception with specified HTTP status.

      Parameters:
      status - an HTTP status
    • HttpException

      public HttpException(Status status, String message)

      Creates an HTTP exception with specified HTTP status and message.

      Parameters:
      status - an HTTP status
      message - a message
    • HttpException

      public HttpException(Status status, Throwable cause)

      Creates an HTTP exception with specified HTTP status and cause.

      Parameters:
      status - an HTTP status
      cause - a cause
    • HttpException

      public HttpException(Status status, String message, Throwable cause)

      Creates an HTTP exception with specified HTTP status, message and cause.

      Parameters:
      status - an HTTP status
      message - a message
      cause - a cause
  • Method Details

    • getStatus

      public Status getStatus()

      Returns the HTTP status.

      Returns:
      an HTTP status or null if the code specified does correspond to any known status
    • getStatusCode

      public int getStatusCode()

      Returns the HTTP status code.

      Returns:
      an HTTP status code
    • getStatusReasonPhrase

      public String getStatusReasonPhrase()

      Returns the HTTP status reason phrase.

      Returns:
      a reason phrase
    • getStatusCategory

      public Status.Category getStatusCategory()

      Returns the HTTP status category.

      Returns:
      an HTTP status category
    • wrap

      public static HttpException wrap(Throwable error)

      Wraps the specified error into an HttpException.

      The specified error is returned untouched if it is already an HttpException instance, ohterwise it is wrapped in an InternalServerErrorException.

      Parameters:
      error - the error to wrap
      Returns:
      the specified error if it is an HttpException, an HttpException wrapping the specified error otherwise