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.rest.client; 018 019import java.io.*; 020 021/** 022 * Exception thrown when an HTTP call fails at the REST client level (e.g. unexpected status code, body 023 * deserialization failure, or interceptor rejection). 024 * 025 * <p> 026 * Network-level failures are reported as {@link TransportException}. 027 * 028 * @since 9.2.1 029 */ 030public class RestCallException extends IOException { 031 032 private static final long serialVersionUID = 1L; 033 034 private final int statusCode; 035 036 /** 037 * Constructor — for cases without an HTTP status code (e.g. deserialization failure). 038 * 039 * @param message The error message. 040 * @param cause The underlying cause. May be <jk>null</jk>. 041 */ 042 public RestCallException(String message, Throwable cause) { 043 super(message, cause); 044 this.statusCode = -1; 045 } 046 047 /** 048 * Constructor — for cases with an HTTP status code (e.g. unexpected 4xx/5xx). 049 * 050 * @param statusCode The HTTP status code. 051 * @param message The error message. 052 */ 053 public RestCallException(int statusCode, String message) { 054 super(message); 055 this.statusCode = statusCode; 056 } 057 058 /** 059 * Constructor — for cases with an HTTP status code and a cause. 060 * 061 * @param statusCode The HTTP status code. 062 * @param message The error message. 063 * @param cause The underlying cause. May be <jk>null</jk>. 064 */ 065 public RestCallException(int statusCode, String message, Throwable cause) { 066 super(message, cause); 067 this.statusCode = statusCode; 068 } 069 070 /** 071 * Returns the HTTP status code, or {@code -1} if not applicable. 072 * 073 * @return The status code. 074 */ 075 public int getStatusCode() { 076 return statusCode; 077 } 078}