1 /* 2 * #%L 3 * wcm.io 4 * %% 5 * Copyright (C) 2014 wcm.io 6 * %% 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * #L% 19 */ 20 package io.wcm.caravan.pipeline; 21 22 import org.osgi.annotation.versioning.ProviderType; 23 24 /** 25 * Used to indicate that the JSON input data of a {@link JsonPipeline} could not be retrieved, was invalid JSON, or 26 * didn't match the expected data structure. 27 */ 28 @ProviderType 29 public final class JsonPipelineInputException extends RuntimeException { 30 31 private static final long serialVersionUID = 1L; 32 33 private final int statusCode; 34 35 private String reason; 36 37 /** 38 * @param statusCode the status code to use in the HTTP response 39 * @param msg the error message (that will also be used as reason string in the HTTP response) 40 */ 41 public JsonPipelineInputException(int statusCode, String msg) { 42 super(msg); 43 this.statusCode = statusCode; 44 } 45 46 /** 47 * @param statusCode the status code to use in the HTTP response 48 * @param msg the error message (that will also be used as reason string in the HTTP response) 49 * @param cause Cause 50 */ 51 public JsonPipelineInputException(int statusCode, String msg, Throwable cause) { 52 super(msg, cause); 53 this.statusCode = statusCode; 54 } 55 56 /** 57 * Provides the appropriate status code for this exception. If the underlying HTTP request fails, the status code will 58 * be taken from the HTTP response. If JSON parsing or object mapping failed, the status code will be 500. 59 * @return the HTTP status code 60 */ 61 public int getStatusCode() { 62 return statusCode; 63 } 64 65 /** 66 * @return exception reason. 67 */ 68 public String getReason() { 69 return reason; 70 } 71 72 /** 73 * @param reasonPhrase the reason line from the HTTP response headers 74 * @return this 75 */ 76 public JsonPipelineInputException setReason(String reasonPhrase) { 77 this.reason = reasonPhrase; 78 return this; 79 } 80 }