Convert Model Exception to Runtime Exception
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfModelRuntimeException.java
index 4724128..cd0562f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.policy.models.base;
 
 import javax.ws.rs.core.Response;
-
 import lombok.Getter;
 import lombok.ToString;
-
 import org.onap.policy.models.errors.concepts.ErrorResponse;
 import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
 import org.onap.policy.models.errors.concepts.ErrorResponseUtils;
@@ -78,6 +76,18 @@ public class PfModelRuntimeException extends RuntimeException implements ErrorRe
         this(statusCode, message, exception, null);
     }
 
+    /**
+     * Instantiates a new model runtime exception from a PfModelException instance.
+     *
+     * @param exception the exception that caused this model exception
+     */
+    public PfModelRuntimeException(final PfModelException exception) {
+        super(exception.getMessage(), exception);
+        this.object = exception.getObject();
+        errorResponse.setResponseCode(exception.getErrorResponse().getResponseCode());
+        ErrorResponseUtils.getExceptionMessages(errorResponse, this);
+    }
+
     /**
      * Instantiates a new model runtime exception.
      *