001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.client;
007
008import java.net.URI;
009
010/**
011 * Represents a failure of the underlying HTTP client's interaction with fedora.
012 *
013 * @author Aaron Coburn
014 * @since January 8, 2015
015 */
016public class FcrepoOperationFailedException extends Exception {
017
018    private final URI url;
019    private final int statusCode;
020    private final String statusText;
021
022    /**
023     * Create an FcrepoOperationFailedException
024     *
025     * @param url the requested url
026     * @param statusCode the HTTP response code
027     * @param statusText the response message
028     */
029    public FcrepoOperationFailedException(final URI url, final int statusCode, final String statusText) {
030        super("HTTP operation failed invoking " + (url != null ? url.toString() : "[null]") +
031                " with statusCode: " + statusCode + " and message: " + statusText);
032        this.url = url;
033        this.statusCode = statusCode;
034        this.statusText = statusText;
035    }
036
037    /**
038     * Return the requested url
039     *
040     * @return the requested URL
041     */
042    public URI getUrl() {
043        return url;
044    }
045
046    /**
047     * Get the status code
048     *
049     * @return the HTTP status code
050     */
051    public int getStatusCode() {
052        return statusCode;
053    }
054
055    /**
056     * Get the status text
057     *
058     * @return the status text for the error
059     */
060    public String getStatusText() {
061        return statusText;
062    }
063}