Predefined Exceptions

Exceptions are defined for all standardized HTTP responses. These can be used to trigger HTTP errors simply by throwing an exception.

These are identical in behavior to the Predefined Responses in the previous section, except these are meant to be thrown instead of returned.

##### Example:

@RestMethod(name="GET", path="/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; }

- {@link oaj.http.exception}
  - {@link oaj.http.exception.BadRequest}
  - {@link oaj.http.exception.Conflict}
  - {@link oaj.http.exception.ExpectationFailed}
  - {@link oaj.http.exception.FailedDependency}
  - {@link oaj.http.exception.Forbidden}
  - {@link oaj.http.exception.Gone}
  - {@link oaj.http.exception.HttpVersionNotSupported}
  - {@link oaj.http.exception.InsufficientStorage}
  - {@link oaj.http.exception.InternalServerError}
  - {@link oaj.http.exception.LengthRequired}
  - {@link oaj.http.exception.Locked}
  - {@link oaj.http.exception.LoopDetected}
  - {@link oaj.http.exception.MethodNotAllowed}
  - {@link oaj.http.exception.MisdirectedRequest}
  - {@link oaj.http.exception.NetworkAuthenticationRequired}
  - {@link oaj.http.exception.NotAcceptable}
  - {@link oaj.http.exception.NotExtended}
  - {@link oaj.http.exception.NotFound}
  - {@link oaj.http.exception.NotImplemented}
  - {@link oaj.http.exception.PayloadTooLarge}
  - {@link oaj.http.exception.PreconditionFailed}
  - {@link oaj.http.exception.PreconditionRequired}
  - {@link oaj.http.exception.RangeNotSatisfiable}
  - {@link oaj.http.exception.RequestHeaderFieldsTooLarge}
  - {@link oaj.http.exception.ServiceUnavailable}
  - {@link oaj.http.exception.TooManyRequests}
  - {@link oaj.http.exception.Unauthorized}
  - {@link oaj.http.exception.UnavailableForLegalReasons}
  - {@link oaj.http.exception.UnprocessableEntity}
  - {@link oaj.http.exception.UnsupportedMediaType}
  - {@link oaj.http.exception.UpgradeRequired}
  - {@link oaj.http.exception.UriTooLong}
  - {@link oaj.http.exception.VariantAlsoNegotiates}

These exception extend from {@link java.lang.RuntimeException}, so they can optionally be specified in the thrown declaration of the method. The important distinction is that when part of the thrown declaration, they show up in the generated Swagger documentation, whereas they don't if not. This behavior can be used to define what error conditions show in your Swagger doc.