001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.exception;
014
015import static org.apache.juneau.rest.exception.TooManyRequests.*;
016
017import java.text.*;
018
019import org.apache.juneau.http.annotation.*;
020import org.apache.juneau.rest.*;
021
022/**
023 * Exception representing an HTTP 429 (Too Many Requests).
024 *
025 * <p>
026 * The user has sent too many requests in a given amount of time.
027 * <br>Intended for use with rate-limiting schemes.
028 */
029@Response(code=CODE, description=MESSAGE)
030public class TooManyRequests extends RestException {
031   private static final long serialVersionUID = 1L;
032
033   /** HTTP status code */
034   public static final int CODE = 429;
035
036   /** Default message */
037   public static final String MESSAGE = "Too Many Requests";
038
039   /**
040    * Constructor.
041    *
042    * @param cause The cause.  Can be <jk>null</jk>.
043    * @param msg The message.  Can be <jk>null</jk>.
044    * @param args Optional {@link MessageFormat}-style arguments in the message.
045    */
046   public TooManyRequests(Throwable cause, String msg, Object...args) {
047      super(cause, CODE, msg, args);
048   }
049
050   /**
051    * Constructor.
052    *
053    * @param msg The message.  Can be <jk>null</jk>.
054    */
055   public TooManyRequests(String msg) {
056      super(msg);
057      setStatus(CODE);
058   }
059
060   /**
061    * Constructor.
062    */
063   public TooManyRequests() {
064      this((Throwable)null, MESSAGE);
065   }
066
067   /**
068    * Constructor.
069    *
070    * @param msg The message.  Can be <jk>null</jk>.
071    * @param args Optional {@link MessageFormat}-style arguments in the message.
072    */
073   public TooManyRequests(String msg, Object...args) {
074      this(null, msg, args);
075   }
076
077   /**
078    * Constructor.
079    *
080    * @param cause The cause.  Can be <jk>null</jk>.
081    */
082   public TooManyRequests(Throwable cause) {
083      this(cause, null);
084   }
085}