Convert Model Exception to Runtime Exception
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfModelRuntimeException.java
index 5c317d1..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.
@@ -76,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.
      *