summaryrefslogtreecommitdiffstats
path: root/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/BaseException.java
diff options
context:
space:
mode:
Diffstat (limited to 'dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/BaseException.java')
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/BaseException.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/BaseException.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/BaseException.java
new file mode 100644
index 0000000..b559634
--- /dev/null
+++ b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/BaseException.java
@@ -0,0 +1,61 @@
+package org.onap.sdc.dcae.errormng;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.google.gson.Gson;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpClientErrorException;
+
+public class BaseException extends HttpClientErrorException {
+
+ private static Gson gson = new Gson();
+
+ protected RequestError requestError;
+
+ public RequestError getRequestError() {
+ return requestError;
+ }
+
+ public void setRequestError(RequestError requestError) {
+ this.requestError = requestError;
+ }
+
+ public BaseException(HttpClientErrorException theError) {
+ super(theError.getStatusCode());
+ String body = theError.getResponseBodyAsString();
+ if (body != null) {
+ requestError = extractRequestError(body);
+ }
+ }
+
+ public BaseException(HttpStatus status, RequestError re){
+ super(status);
+ requestError = re;
+ }
+
+ private RequestError extractRequestError(String error) {
+ ResponseFormat responseFormat = gson.fromJson(error, ResponseFormat.class);
+ return responseFormat.getRequestError();
+ }
+
+ @JsonIgnore
+ public String getMessageId() {
+ return requestError.getMessageId();
+ }
+
+ @JsonIgnore
+ public String[] getVariables() {
+ return requestError.getVariables();
+ }
+
+ @JsonIgnore
+ public String getText(){
+ return requestError.getText();
+ }
+
+ @Override
+ @JsonIgnore
+ public String getMessage() {
+ return requestError.getFormattedMessage();
+ }
+
+} \ No newline at end of file