1 package org.onap.vid.aai;
3 import org.apache.commons.lang3.StringUtils;
4 import org.springframework.http.HttpMethod;
6 import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
8 public class ExceptionWithRequestInfo extends RuntimeException {
10 private final HttpMethod httpMethod;
11 private final String requestedUrl;
12 private final Integer httpCode;
13 private final String rawData;
15 public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, String rawData, Integer httpCode, Throwable cause) {
16 super(toMessage(httpMethod, requestedUrl, cause), cause);
17 this.httpMethod = httpMethod;
18 this.requestedUrl = requestedUrl;
19 this.rawData = rawData;
20 this.httpCode = httpCode;
23 public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
24 this(httpMethod, requestedUrl, null, null, cause);
27 public String getRequestedUrl() {
31 public String getRawData() {
35 public HttpMethod getHttpMethod() {
39 public Integer getHttpCode() {
43 private static String toMessage(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
44 if (StringUtils.isEmpty(requestedUrl)) {
45 return cause.toString();
48 "Exception while handling " +
49 defaultIfNull(httpMethod, "request").toString() +
51 ": " + cause.toString();