2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
21 package org.onap.vid.aai;
23 import org.apache.commons.lang3.StringUtils;
24 import org.springframework.http.HttpMethod;
26 import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
28 public class ExceptionWithRequestInfo extends RuntimeException {
30 private final HttpMethod httpMethod;
31 private final String requestedUrl;
32 private final Integer httpCode;
33 private final String rawData;
35 public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, String rawData, Integer httpCode, Throwable cause) {
36 super(toMessage(httpMethod, requestedUrl, cause), cause);
37 this.httpMethod = httpMethod;
38 this.requestedUrl = requestedUrl;
39 this.rawData = rawData;
40 this.httpCode = httpCode;
43 public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
44 this(httpMethod, requestedUrl, null, null, cause);
47 public String getRequestedUrl() {
51 public String getRawData() {
55 public HttpMethod getHttpMethod() {
59 public Integer getHttpCode() {
63 private static String toMessage(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
64 if (StringUtils.isEmpty(requestedUrl)) {
65 return String.valueOf(cause);
68 "Exception while handling " +
69 defaultIfNull(httpMethod, "request").toString() +
71 ": " + (cause == null ? "null" : cause.toString());