Class HttpException

Object
akka.javasdk.http.HttpException

public final class HttpException extends Object
Factory class for creating HTTP exceptions that result in specific HTTP error responses.

HttpException provides static factory methods for creating exceptions that, when thrown from HTTP endpoint methods, are automatically converted to appropriate HTTP error responses with the corresponding status codes.

Common Error Responses:

Custom Status Codes: Use error(akka.http.javadsl.model.StatusCode) for arbitrary HTTP status codes not covered by the predefined factory methods.

Error Messages: Most factory methods have overloads that accept a response text parameter to provide additional error details to the client.

Alternative Error Handling:

  • IllegalArgumentException is automatically converted to 400 Bad Request
  • Other exceptions become 500 Internal Server Error
  • Return HttpResponses error methods for more control
  • Method Details

    • badRequest

      public static RuntimeException badRequest()
    • badRequest

      public static RuntimeException badRequest(String responseText)
    • notFound

      public static RuntimeException notFound()
    • forbidden

      public static RuntimeException forbidden()
    • forbidden

      public static RuntimeException forbidden(String responseText)
    • unauthorized

      public static RuntimeException unauthorized()
    • unauthorized

      public static RuntimeException unauthorized(String responseText)
    • notImplemented

      public static RuntimeException notImplemented()
    • error

      public static RuntimeException error(akka.http.javadsl.model.StatusCode statusCode)
      Returns:
      An exception with an arbitrary HTTP status code.

      Note: a large list of predefined status codes can be found in StatusCodes

    • error

      public static RuntimeException error(akka.http.javadsl.model.StatusCode statusCode, String responseText)
      Returns:
      An exception with an arbitrary HTTP status code.

      Note: a large list of predefined status codes can be found in StatusCodes