summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java
new file mode 100644
index 00000000..dcca3ec4
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java
@@ -0,0 +1,54 @@
+package org.onap.vid.aai;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.http.HttpMethod;
+
+import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
+
+public class ExceptionWithRequestInfo extends RuntimeException {
+
+ private final HttpMethod httpMethod;
+ private final String requestedUrl;
+ private final Integer httpCode;
+ private final String rawData;
+
+ public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, String rawData, Integer httpCode, Throwable cause) {
+ super(toMessage(httpMethod, requestedUrl, cause), cause);
+ this.httpMethod = httpMethod;
+ this.requestedUrl = requestedUrl;
+ this.rawData = rawData;
+ this.httpCode = httpCode;
+ }
+
+ public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
+ this(httpMethod, requestedUrl, null, null, cause);
+ }
+
+ public String getRequestedUrl() {
+ return requestedUrl;
+ }
+
+ public String getRawData() {
+ return rawData;
+ }
+
+ public HttpMethod getHttpMethod() {
+ return httpMethod;
+ }
+
+ public Integer getHttpCode() {
+ return httpCode;
+ }
+
+ private static String toMessage(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
+ if (StringUtils.isEmpty(requestedUrl)) {
+ return cause.toString();
+ } else {
+ return "" +
+ "Exception while handling " +
+ defaultIfNull(httpMethod, "request").toString() +
+ " " + requestedUrl +
+ ": " + cause.toString();
+ }
+ }
+}