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 oajr.exception}
  - {@link oajr.exception.BadRequest}
  - {@link oajr.exception.Conflict}
  - {@link oajr.exception.ExpectationFailed}
  - {@link oajr.exception.FailedDependency}
  - {@link oajr.exception.Forbidden}
  - {@link oajr.exception.Gone}
  - {@link oajr.exception.HttpVersionNotSupported}
  - {@link oajr.exception.InsufficientStorage}
  - {@link oajr.exception.InternalServerError}
  - {@link oajr.exception.LengthRequired}
  - {@link oajr.exception.Locked}
  - {@link oajr.exception.LoopDetected}
  - {@link oajr.exception.MethodNotAllowed}
  - {@link oajr.exception.MisdirectedRequest}
  - {@link oajr.exception.NetworkAuthenticationRequired}
  - {@link oajr.exception.NotAcceptable}
  - {@link oajr.exception.NotExtended}
  - {@link oajr.exception.NotFound}
  - {@link oajr.exception.NotImplemented}
  - {@link oajr.exception.PayloadTooLarge}
  - {@link oajr.exception.PreconditionFailed}
  - {@link oajr.exception.PreconditionRequired}
  - {@link oajr.exception.RangeNotSatisfiable}
  - {@link oajr.exception.RequestHeaderFieldsTooLarge}
  - {@link oajr.exception.ServiceUnavailable}
  - {@link oajr.exception.TooManyRequests}
  - {@link oajr.exception.Unauthorized}
  - {@link oajr.exception.UnavailableForLegalReasons}
  - {@link oajr.exception.UnprocessableEntity}
  - {@link oajr.exception.UnsupportedMediaType}
  - {@link oajr.exception.UpgradeRequired}
  - {@link oajr.exception.UriTooLong}
  - {@link oajr.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.