| <!-- |
| /*************************************************************************************************************************** |
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations under the License. |
| ***************************************************************************************************************************/ |
| --> |
| |
| Predefined Exceptions |
| |
| <p> |
| Exceptions are defined for all standardized HTTP responses. |
| These can be used to trigger HTTP errors simply by throwing an exception. |
| </p> |
| <p> |
| These are identical in behavior to the Predefined Responses in the previous section, except these are meant |
| to be thrown instead of returned. |
| </p> |
| <h5 class='figure'>Example:</h5> |
| <p class='bpcode w800'> |
| <ja>@RestMethod</ja>(name=<js>"GET"</js>, path=<js>"/user/login"</js>) |
| <jk>public</jk> Ok login( |
| <ja>@FormData</ja>(<js>"username"</js>) String username, |
| <ja>@FormData</ja>(<js>"password"</js>) String password, |
| ) <jk>throws</jk> Unauthorized |
| { |
| <jk>if</jk> (! <jsm>isOK</jsm>(username, password)) |
| <jk>throw new</jk> Unauthorized(<js>"You're not welcome!"</js>); |
| |
| <jk>return</jk> Ok.<jsf>OK</jsf>; |
| } |
| </p> |
| <ul class='javatree'> |
| <li class='jp'>{@link oajr.exception} |
| <ul> |
| <li class='jc'>{@link oajr.exception.BadRequest} |
| <li class='jc'>{@link oajr.exception.Conflict} |
| <li class='jc'>{@link oajr.exception.ExpectationFailed} |
| <li class='jc'>{@link oajr.exception.FailedDependency} |
| <li class='jc'>{@link oajr.exception.Forbidden} |
| <li class='jc'>{@link oajr.exception.Gone} |
| <li class='jc'>{@link oajr.exception.HttpVersionNotSupported} |
| <li class='jc'>{@link oajr.exception.InsufficientStorage} |
| <li class='jc'>{@link oajr.exception.InternalServerError} |
| <li class='jc'>{@link oajr.exception.LengthRequired} |
| <li class='jc'>{@link oajr.exception.Locked} |
| <li class='jc'>{@link oajr.exception.LoopDetected} |
| <li class='jc'>{@link oajr.exception.MethodNotAllowed} |
| <li class='jc'>{@link oajr.exception.MisdirectedRequest} |
| <li class='jc'>{@link oajr.exception.NetworkAuthenticationRequired} |
| <li class='jc'>{@link oajr.exception.NotAcceptable} |
| <li class='jc'>{@link oajr.exception.NotExtended} |
| <li class='jc'>{@link oajr.exception.NotFound} |
| <li class='jc'>{@link oajr.exception.NotImplemented} |
| <li class='jc'>{@link oajr.exception.PayloadTooLarge} |
| <li class='jc'>{@link oajr.exception.PreconditionFailed} |
| <li class='jc'>{@link oajr.exception.PreconditionRequired} |
| <li class='jc'>{@link oajr.exception.RangeNotSatisfiable} |
| <li class='jc'>{@link oajr.exception.RequestHeaderFieldsTooLarge} |
| <li class='jc'>{@link oajr.exception.ServiceUnavailable} |
| <li class='jc'>{@link oajr.exception.TooManyRequests} |
| <li class='jc'>{@link oajr.exception.Unauthorized} |
| <li class='jc'>{@link oajr.exception.UnavailableForLegalReasons} |
| <li class='jc'>{@link oajr.exception.UnprocessableEntity} |
| <li class='jc'>{@link oajr.exception.UnsupportedMediaType} |
| <li class='jc'>{@link oajr.exception.UpgradeRequired} |
| <li class='jc'>{@link oajr.exception.UriTooLong} |
| <li class='jc'>{@link oajr.exception.VariantAlsoNegotiates} |
| </ul> |
| </ul> |
| <p> |
| 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. |
| </p> |