001/**
002 * Copyright 2015 DuraSpace, Inc.
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 *     http://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 */
016package org.fcrepo.client;
017
018import java.net.URI;
019
020/**
021 * Represents a failure of the underlying HTTP client's interaction with fedora.
022 *
023 * @author Aaron Coburn
024 * @since January 8, 2015
025 */
026public class FcrepoOperationFailedException extends Exception {
027
028    private final URI url;
029    private final int statusCode;
030    private final String statusText;
031
032    /**
033     * Create an FcrepoOperationFailedException
034     *
035     * @param url the requested url
036     * @param statusCode the HTTP response code
037     * @param statusText the response message
038     */
039    public FcrepoOperationFailedException(final URI url, final int statusCode, final String statusText) {
040        super("HTTP operation failed invoking " + (url != null ? url.toString() : "[null]") +
041                " with statusCode: " + statusCode + " and message: " + statusText);
042        this.url = url;
043        this.statusCode = statusCode;
044        this.statusText = statusText;
045    }
046
047    /**
048     * Return the requested url
049     *
050     * @return the requested URL
051     */
052    public URI getUrl() {
053        return url;
054    }
055
056    /**
057     * Get the status code
058     *
059     * @return the HTTP status code
060     */
061    public int getStatusCode() {
062        return statusCode;
063    }
064
065    /**
066     * Get the status text
067     *
068     * @return the status text for the error
069     */
070    public String getStatusText() {
071        return statusText;
072    }
073}