Skip to content

Commit

Permalink
Improve error handling in getGovernanceConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshan-Banneheke committed Aug 22, 2023
1 parent 9c31920 commit e432932
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public enum ErrorMessage {
ERROR_CODE_INCORRECT_CONNECTOR_NAME("50011", "Invalid connector name",
"Unable to find a connector with the name %s."),
ERROR_CODE_UNSUPPORTED_PROPERTY_NAME("50012", "Unsupported property is requested.",
"The property %s is not supported by this API.");
"The property %s is not supported by this API."),

ERROR_CODE_CONNECTOR_CATEGORY_MISMATCH("50013", "Connector category mismatch.",
"The connector %s does not belong to the category %s.");

private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public ConnectorRes getGovernanceConnector(String categoryId, String connectorId
.withoutPadding()
.encodeToString(connectorConfig.getCategory().getBytes(StandardCharsets.UTF_8));
if (!categoryId.equals(categoryIdFound)) {
throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND);
throw handleMismatchError(connectorId, categoryId,
GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_CATEGORY_MISMATCH);
}

return buildConnectorResDTO(connectorConfig);
Expand Down Expand Up @@ -508,4 +509,14 @@ private APIError handleNotFoundError(String resourceId,

return new APIError(status, errorResponse);
}

private APIError handleMismatchError(String connectorId, String categoryId,
GovernanceConstants.ErrorMessage errorMessage) {

Response.Status status = Response.Status.BAD_REQUEST;
ErrorResponse errorResponse =
getErrorBuilder(errorMessage, connectorId, categoryId).build(LOG, errorMessage.getDescription());

return new APIError(status, errorResponse);
}
}

0 comments on commit e432932

Please sign in to comment.