diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Default/APICreateDefault.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Default/APICreateDefault.jsx
index b057d27ad52..c51d032ef33 100644
--- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Default/APICreateDefault.jsx
+++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Default/APICreateDefault.jsx
@@ -36,6 +36,7 @@ import DefaultAPIForm from 'AppComponents/Apis/Create/Components/DefaultAPIForm'
import APIProduct from 'AppData/APIProduct';
import AuthManager from 'AppData/AuthManager';
import Progress from 'AppComponents/Shared/Progress';
+import Utils from 'AppData/Utils';
const gatewayTypeMap = {
'Regular': 'wso2/synapse',
@@ -293,14 +294,45 @@ function APICreateDefault(props) {
error: (error) => {
console.error(error);
if (error.response) {
- // TODO: Use the code to check for the governance error
if (error.response.body.code === complianceErrorCode) {
- // TODO: Check whether we need to display the violations table
- // TODO: Improve the error alert
- return intl.formatMessage({
- id: 'Apis.Create.Default.APICreateDefault.error.governance.violation',
- defaultMessage: 'Revision creation failed due to governance violations',
- });
+ const violations = JSON.parse(error.response.body.description).blockingViolations;
+ return (
+
+
+
+
+
+
+
+
+ )
} else {
setPageError(error.response.body);
return error.response.body.description;
@@ -369,14 +401,45 @@ function APICreateDefault(props) {
error: (error) => {
console.error(error);
if (error.response) {
- // TODO: Use the code to check for the governance error
if (error.response.body.code === complianceErrorCode) {
- // TODO: Check whether we need to display the violations list
- // TODO: Improve the error alert
- return intl.formatMessage({
- id: 'Apis.Create.Default.APICreateDefault.error.governance.violation',
- defaultMessage: 'Deployment failed due to governance violations',
- });
+ const violations = JSON.parse(error.response.body.description).blockingViolations;
+ return (
+
+
+
+
+
+
+
+
+ )
} else {
setPageError(error.response.body);
return error.response.body.description;
@@ -419,10 +482,55 @@ function APICreateDefault(props) {
});
}
},
- error: () => intl.formatMessage({
- id: 'Apis.Create.Default.APICreateDefault.error.otherStatus',
- defaultMessage: 'Error while publishing the API',
- }),
+ error: (error) => {
+ if (error.response.body.code === complianceErrorCode) {
+ const violations = JSON.parse(error.response.body.description).blockingViolations;
+ return (
+
+
+
+
+
+
+
+
+ )
+ } else {
+ return intl.formatMessage({
+ id: 'Apis.Create.Default.APICreateDefault.error.otherStatus',
+ defaultMessage: 'Error while publishing the API',
+ })
+ }
+ },
});
promisedPublish.then(() => history.push(`/apis/${api.id}/overview`))
.finally(() => {
diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/StreamingAPI/APICreateStreamingAPI.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/StreamingAPI/APICreateStreamingAPI.jsx
index f2061f06031..e21ce1666cc 100644
--- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/StreamingAPI/APICreateStreamingAPI.jsx
+++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/StreamingAPI/APICreateStreamingAPI.jsx
@@ -34,6 +34,7 @@ import Banner from 'AppComponents/Shared/Banner';
import DefaultAPIForm from 'AppComponents/Apis/Create/Components/DefaultAPIForm';
import { usePublisherSettings } from 'AppComponents/Shared/AppContext';
import AuthManager from 'AppData/AuthManager';
+import Utils from 'AppData/Utils';
const PREFIX = 'APICreateStreamingAPI';
@@ -324,8 +325,54 @@ const APICreateStreamingAPI = (props) => {
})
.catch((error) => {
if (error.response) {
- Alert.error(error.response.body.description);
- setPageError(error.response.body);
+ if (error.response.body.code === complianceErrorCode) {
+ const violations =
+ JSON.parse(error.response.body.description).blockingViolations;
+ Alert.error(
+
+
+
+
+
+
+
+
+ )
+ } else {
+ Alert.error(error.response.body.description);
+ setPageError(error.response.body);
+ }
} else {
Alert.error(intl.formatMessage({
id: 'Apis.Create.Default.APICreateDefault.error.errorMessage.publish',
@@ -342,8 +389,50 @@ const APICreateStreamingAPI = (props) => {
})
.catch((error) => {
if (error.response) {
- Alert.error(error.response.body.description);
- setPageError(error.response.body);
+ if (error.response.body.code === complianceErrorCode) {
+ const violations = JSON.parse(error.response.body.description).blockingViolations;
+ Alert.error(
+
+
+
+
+
+
+
+
+ )
+ } else {
+ Alert.error(error.response.body.description);
+ setPageError(error.response.body);
+ }
} else {
Alert.error(intl.formatMessage({
id: 'Apis.Create.Default.APICreateDefault.error.errorMessage.deploy.revision',
@@ -359,15 +448,46 @@ const APICreateStreamingAPI = (props) => {
})
.catch((error) => {
if (error.response) {
- // TODO: Use the code to check for the governance error
if (error.response.body.code === complianceErrorCode) {
- // TODO: Check whether we need to display the violations list
- // TODO: Improve the error alert
- Alert.error(intl.formatMessage({
- id: 'Apis.Create.Default.APICreateDefault.error.errorMessage.'
- + 'create.revision.governance',
- defaultMessage: 'Action failed due to governance violations',
- }));
+ const violations = JSON.parse(error.response.body.description).blockingViolations;
+ Alert.error(
+
+
+
+
+
+
+
+
+ )
} else {
Alert.error(error.response.body.description);
setPageError(error.response.body);
diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx
index 9b711ddfdfc..ea32581c6f8 100644
--- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx
+++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx
@@ -830,7 +830,6 @@ export default function Environments() {
})
.catch((error) => {
if (error.response) {
- // TODO: Use the error code to identify the errors thrown by governance violation
if (error.response.body.code === complianceErrorCode) {
const violations = JSON.parse(error.response.body.description).blockingViolations;
setGovernanceError(violations);
@@ -852,7 +851,7 @@ export default function Environments() {
}}>
+ onClick={() =>
Utils.downloadAsJSON(violations, 'governance-violations')
}
sx={{
@@ -1080,6 +1079,7 @@ export default function Environments() {
displayOnDevportal,
vhost,
}];
+ let isBlockedByGovernanceViolation = false;
if (api.apiType !== API.CONSTS.APIProduct) {
setIsDeploying(true);
restApi.deployRevision(api.id, revisionId, body).then((response) => {
@@ -1098,8 +1098,8 @@ export default function Environments() {
}
}).catch((error) => {
if (error.response) {
- // TODO: Use the error code to identify the errors thrown by governance violation
if (error.response.body.code === complianceErrorCode) {
+ isBlockedByGovernanceViolation = true;
const violations = JSON.parse(error.response.body.description).blockingViolations;
setGovernanceError(violations);
setIsGovernanceViolation(true);
@@ -1151,8 +1151,11 @@ export default function Environments() {
}
console.error(error);
}).finally(() => {
- getRevision();
- getDeployedEnv();
+ // Only refresh the page if there's no governance violation
+ if (!isBlockedByGovernanceViolation) {
+ getRevision();
+ getDeployedEnv();
+ }
setIsDeploying(false);
});
} else {
@@ -1213,7 +1216,6 @@ export default function Environments() {
})
.catch((error) => {
if (error.response) {
- // TODO: Use the error code to identify the errors thrown by governance violation
if (error.response.body.code === complianceErrorCode) {
const violations = JSON.parse(error.response.body.description).blockingViolations;
setGovernanceError(violations);
@@ -1235,7 +1237,7 @@ export default function Environments() {
}}>
+ onClick={() =>
Utils.downloadAsJSON(violations, 'governance-violations')
}
sx={{
@@ -1279,7 +1281,6 @@ export default function Environments() {
})
.catch((error) => {
if (error.response) {
- // TODO: Use the error code to identify the errors thrown by governance violation
if (error.response.body.code === complianceErrorCode) {
const violations = JSON.parse(error.response.body.description).blockingViolations;
setGovernanceError(violations);
@@ -1322,6 +1323,7 @@ export default function Environments() {
);
+ setOpenDeployPopup(false);
return;
} else {
Alert.error(error.response.body.description);
diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Listing/SampleAPI/components/TaskState.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Listing/SampleAPI/components/TaskState.jsx
index b77be2824fc..8698cfd31d0 100644
--- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Listing/SampleAPI/components/TaskState.jsx
+++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Listing/SampleAPI/components/TaskState.jsx
@@ -12,6 +12,7 @@ import CircularProgress from '@mui/material/CircularProgress';
* @return {*}
*/
export default function TaskState(props) {
+ const complianceErrorCode = 903300;
const {
pending, completed, errors, inProgress, children, pendingMessage, completedMessage, inProgressMessage,
} = props;
@@ -39,8 +40,7 @@ export default function TaskState(props) {
severity = 'error';
if (errors.response) {
const { body } = errors.response;
- if (body.description && body.description.includes('violatedPath')) {
- // TODO: Use the code for governance violations
+ if (body.code === complianceErrorCode) {
message = (
<>
Governance Policy Violation
@@ -48,7 +48,7 @@ export default function TaskState(props) {
>
);