| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.atmos; |
| 20 | |
| 21 | import org.jclouds.atmos.domain.AtmosError; |
| 22 | import org.jclouds.atmos.handlers.ParseAtmosErrorFromXmlContent; |
| 23 | import org.jclouds.http.HttpCommand; |
| 24 | import org.jclouds.http.HttpResponse; |
| 25 | import org.jclouds.http.HttpResponseException; |
| 26 | |
| 27 | /** |
| 28 | * Encapsulates an Error from Atmos Storage Services. |
| 29 | * |
| 30 | * @see AtmosError |
| 31 | * @see ParseAtmosErrorFromXmlContent |
| 32 | * @author Adrian Cole |
| 33 | * |
| 34 | */ |
| 35 | public class AtmosResponseException extends HttpResponseException { |
| 36 | |
| 37 | private static final long serialVersionUID = 1L; |
| 38 | |
| 39 | private AtmosError error; |
| 40 | |
| 41 | public AtmosResponseException(HttpCommand command, HttpResponse response, |
| 42 | AtmosError error) { |
| 43 | super(String.format("command %s failed with code %s, error: %s", command.getCurrentRequest() |
| 44 | .getRequestLine(), response.getStatusCode(), error.toString()), command, response); |
| 45 | this.setError(error); |
| 46 | |
| 47 | } |
| 48 | |
| 49 | public AtmosResponseException(HttpCommand command, HttpResponse response, |
| 50 | AtmosError error, Throwable cause) { |
| 51 | super(String.format("command %1$s failed with error: %2$s", command.getCurrentRequest() |
| 52 | .getRequestLine(), error.toString()), command, response, cause); |
| 53 | this.setError(error); |
| 54 | |
| 55 | } |
| 56 | |
| 57 | public AtmosResponseException(String message, HttpCommand command, HttpResponse response, |
| 58 | AtmosError error) { |
| 59 | super(message, command, response); |
| 60 | this.setError(error); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | public AtmosResponseException(String message, HttpCommand command, HttpResponse response, |
| 65 | AtmosError error, Throwable cause) { |
| 66 | super(message, command, response, cause); |
| 67 | this.setError(error); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | public void setError(AtmosError error) { |
| 72 | this.error = error; |
| 73 | } |
| 74 | |
| 75 | public AtmosError getError() { |
| 76 | return error; |
| 77 | } |
| 78 | |
| 79 | } |