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.objecttools; 014 015import java.net.*; 016import java.text.*; 017 018import org.apache.juneau.*; 019 020/** 021 * Generic exception thrown from the {@link ObjectRest} class. 022 * 023 * <p> 024 * Typically, this is a user-error, such as trying to address a non-existent node in the tree. 025 * 026 * <p> 027 * The status code is an HTTP-equivalent code. It will be one of the following: 028 * <ul class='spaced-list'> 029 * <li> 030 * {@link HttpURLConnection#HTTP_BAD_REQUEST HTTP_BAD_REQUEST} 031 * - Attempting to do something impossible. 032 * <li> 033 * {@link HttpURLConnection#HTTP_NOT_FOUND HTTP_NOT_FOUND} 034 * - Attempting to access a non-existent node in the tree. 035 * <li> 036 * {@link HttpURLConnection#HTTP_FORBIDDEN HTTP_FORBIDDEN} 037 * - Attempting to overwrite the root object. 038 * </ul> 039 * 040 * <h5 class='section'>See Also:</h5><ul> 041 042 * </ul> 043 * 044 * @serial exclude 045 */ 046public final class ObjectRestException extends BasicRuntimeException { 047 048 private static final long serialVersionUID = 1L; 049 050 private int status; 051 052 /** 053 * Constructor. 054 * 055 * @param cause The cause of this exception. 056 * @param status HTTP status code. 057 * @param message The {@link MessageFormat}-style message. 058 * @param args Optional {@link MessageFormat}-style arguments. 059 */ 060 public ObjectRestException(Throwable cause, int status, String message, Object... args) { 061 super(cause, message, args); 062 this.status = status; 063 } 064 065 /** 066 * Constructor. 067 * 068 * @param status The HTTP-equivalent status code. 069 * @param message The detailed message. 070 * @param args Optional {@link MessageFormat}-style arguments. 071 */ 072 public ObjectRestException(int status, String message, Object...args) { 073 this(null, status, message, args); 074 } 075 076 /** 077 * The HTTP-equivalent status code. 078 * 079 * <p> 080 * See above for details. 081 * 082 * @return The HTTP-equivalent status code. 083 */ 084 public int getStatus() { 085 return status; 086 } 087}