Skip to content

Commit

Permalink
Add sub fault categories for schema validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SavinduDimal committed Feb 8, 2024
1 parent 7398788 commit 285d72d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public enum Other implements FaultSubCategory {
MEDIATION_ERROR,
RESOURCE_NOT_FOUND,
METHOD_NOT_ALLOWED,
INVALID_REQUEST_SCHEMA,
INVALID_RESPONSE_SCHEMA,
UNCLASSIFIED
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.wso2.carbon.apimgt.gateway.handlers.analytics;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
Expand Down Expand Up @@ -127,6 +128,10 @@ protected FaultSubCategory getOtherFaultSubCategory(int errorCode) {
return FaultSubCategories.Other.METHOD_NOT_ALLOWED;
} else if (isResourceNotFound()) {
return FaultSubCategories.Other.RESOURCE_NOT_FOUND;
} else if (isRequestSchemaInvalid()) {
return FaultSubCategories.Other.INVALID_REQUEST_SCHEMA;
} else if (isResponseSchemaInvalid()) {
return FaultSubCategories.Other.INVALID_RESPONSE_SCHEMA;
} else {
return FaultSubCategories.Other.UNCLASSIFIED;
}
Expand All @@ -149,4 +154,24 @@ public boolean isMethodNotAllowed() {
}
return false;
}

private boolean isRequestSchemaInvalid() {
if (messageContext.getPropertyKeySet().contains(SynapseConstants.ERROR_DETAIL)) {
String errorDetail = (String) messageContext.getProperty(SynapseConstants.ERROR_DETAIL);
String errorMessage = "Schema validation failed in the Request: ";
return messageContext.getPropertyKeySet().contains(RESTConstants.PROCESSED_API)
&& StringUtils.isNotEmpty(errorDetail) && errorDetail.contains(errorMessage);
}
return false;
}

private boolean isResponseSchemaInvalid() {
if (messageContext.getPropertyKeySet().contains(SynapseConstants.ERROR_DETAIL)) {
String errorDetail = (String) messageContext.getProperty(SynapseConstants.ERROR_DETAIL);
String errorMessage = "Schema validation failed in the Response: ";
return messageContext.getPropertyKeySet().contains(RESTConstants.PROCESSED_API)
&& StringUtils.isNotEmpty(errorDetail) && errorDetail.contains(errorMessage);
}
return false;
}
}
Binary file not shown.

0 comments on commit 285d72d

Please sign in to comment.