Package akka.javasdk.http
Class HttpException
Object
akka.javasdk.http.HttpException
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:
badRequest()- 400 Bad Request for invalid client inputunauthorized()- 401 Unauthorized for authentication failuresforbidden()- 403 Forbidden for authorization failuresnotFound()- 404 Not Found for missing resourcesnotImplemented()- 501 Not Implemented for unsupported operations
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:
IllegalArgumentExceptionis automatically converted to 400 Bad Request- Other exceptions become 500 Internal Server Error
- Return
HttpResponseserror methods for more control
-
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeExceptionstatic RuntimeExceptionbadRequest(String responseText) static RuntimeExceptionerror(akka.http.javadsl.model.StatusCode statusCode) static RuntimeExceptionstatic RuntimeExceptionstatic RuntimeExceptionstatic RuntimeExceptionnotFound()static RuntimeExceptionstatic RuntimeExceptionstatic RuntimeExceptionunauthorized(String responseText)
-
Method Details
-
badRequest
-
badRequest
-
notFound
-
forbidden
-
forbidden
-
unauthorized
-
unauthorized
-
notImplemented
-
error
- 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
-