Skip to main content

Java Method Throwable Types

Annotated Java methods can throw any of the following:

Standard HTTP response beans:

BadRequest Conflict ExpectationFailed FailedDependency Forbidden Gone HttpVersionNotSupported InsufficientStorage InternalServerError LengthRequired Locked LoopDetected MethodNotAllowed MisdirectedRequest NetworkAuthenticationRequired NotAcceptable NotExtended NotFound NotImplemented PayloadTooLarge PreconditionFailed PreconditionRequired RangeNotSatisfiable RequestHeaderFieldsTooLarge ServiceUnavailable TooManyRequests Unauthorized UnavailableForLegalReasons UnprocessableEntity UnsupportedMediaType UpgradeRequired UriTooLong VariantAlsoNegotiates

Annotated throwables:

Response

All other throwables get processed as follows:

Processed as 400/Bad Request:

ParseExceptionInvalidDataConversionException

Processed as 401/Unauthorized:

  • Any class named "AccessDenied" or "Unauthorized"

Processed as 404/Not Found:

  • Any class named "Empty" or "NotFound"

Anything else processed as 500/Internal Server Error.

Example
@RestGet("/user/login")
public Ok login(
@FormData("username") String username,
@FormData("password") String password
) throws Unauthorized
{
if (! isOK(username, password))
throw new Unauthorized("You're not welcome!");

return Ok.OK;
}