Java Method Throwable Types
Annotated Java methods can throw any of the following:
Standard HTTP response beans:
Annotated throwables:
All other throwables get processed as follows:
Processed as 400/Bad Request:
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;
}