001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.objecttools; 018 019import java.net.*; 020import java.text.*; 021 022import org.apache.juneau.*; 023 024/** 025 * Generic exception thrown from the {@link ObjectRest} class. 026 * 027 * <p> 028 * Typically, this is a user-error, such as trying to address a non-existent node in the tree. 029 * 030 * <p> 031 * The status code is an HTTP-equivalent code. It will be one of the following: 032 * <ul class='spaced-list'> 033 * <li> 034 * {@link HttpURLConnection#HTTP_BAD_REQUEST HTTP_BAD_REQUEST} 035 * - Attempting to do something impossible. 036 * <li> 037 * {@link HttpURLConnection#HTTP_NOT_FOUND HTTP_NOT_FOUND} 038 * - Attempting to access a non-existent node in the tree. 039 * <li> 040 * {@link HttpURLConnection#HTTP_FORBIDDEN HTTP_FORBIDDEN} 041 * - Attempting to overwrite the root object. 042 * </ul> 043 * 044 * <h5 class='section'>See Also:</h5><ul> 045 046 * </ul> 047 * 048 * @serial exclude 049 */ 050public class ObjectRestException extends BasicRuntimeException { 051 052 private static final long serialVersionUID = 1L; 053 054 private int status; 055 056 /** 057 * Constructor. 058 * 059 * @param cause The cause of this exception. 060 * @param status HTTP status code. 061 * @param message The {@link MessageFormat}-style message. 062 * @param args Optional {@link MessageFormat}-style arguments. 063 */ 064 public ObjectRestException(Throwable cause, int status, String message, Object... args) { 065 super(cause, message, args); 066 this.status = status; 067 } 068 069 /** 070 * Constructor. 071 * 072 * @param status The HTTP-equivalent status code. 073 * @param message The detailed message. 074 * @param args Optional {@link MessageFormat}-style arguments. 075 */ 076 public ObjectRestException(int status, String message, Object...args) { 077 this(null, status, message, args); 078 } 079 080 /** 081 * The HTTP-equivalent status code. 082 * 083 * <p> 084 * See above for details. 085 * 086 * @return The HTTP-equivalent status code. 087 */ 088 public int getStatus() { 089 return status; 090 } 091}