aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
commitc72d565bb58226b20625b2bce5f0019046bee649 (patch)
tree8658e49595705b02e47ddc14afa20d6bb7123547 /vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java
parentef8a6b47847012fd59ea20da21d8d3d7c4a301ed (diff)
Merge 1806 code of vid-common
Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
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 000000000..dcca3ec4b
--- /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();
+ }
+ }
+}