001/*
002 * Copyright 2002-2019 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.client;
018
019import java.nio.charset.Charset;
020
021import org.springframework.http.HttpHeaders;
022import org.springframework.http.HttpStatus;
023import org.springframework.lang.Nullable;
024
025/**
026 * Exception thrown when an unknown (or custom) HTTP status code is received.
027 *
028 * @author Rossen Stoyanchev
029 * @since 3.2
030 */
031public class UnknownHttpStatusCodeException extends RestClientResponseException {
032
033        private static final long serialVersionUID = 7103980251635005491L;
034
035
036        /**
037         * Construct a new instance of {@code HttpStatusCodeException} based on an
038         * {@link HttpStatus}, status text, and response body content.
039         * @param rawStatusCode the raw status code value
040         * @param statusText the status text
041         * @param responseHeaders the response headers (may be {@code null})
042         * @param responseBody the response body content (may be {@code null})
043         * @param responseCharset the response body charset (may be {@code null})
044         */
045        public UnknownHttpStatusCodeException(int rawStatusCode, String statusText, @Nullable HttpHeaders responseHeaders,
046                        @Nullable byte[] responseBody, @Nullable Charset responseCharset) {
047
048                this("Unknown status code [" + rawStatusCode + "]" + " " + statusText,
049                                rawStatusCode, statusText, responseHeaders, responseBody, responseCharset);
050        }
051
052        /**
053         * Construct a new instance of {@code HttpStatusCodeException} based on an
054         * {@link HttpStatus}, status text, and response body content.
055         * @param rawStatusCode the raw status code value
056         * @param statusText the status text
057         * @param responseHeaders the response headers (may be {@code null})
058         * @param responseBody the response body content (may be {@code null})
059         * @param responseCharset the response body charset (may be {@code null})
060         * @since 5.2.2
061         */
062        public UnknownHttpStatusCodeException(String message, int rawStatusCode, String statusText,
063                        @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) {
064
065                super(message, rawStatusCode, statusText, responseHeaders, responseBody, responseCharset);
066        }
067}