use of org.wso2.carbon.identity.remotefetch.common.exceptions.RemoteFetchClientException in project identity-api-server by wso2.
the class ServerRemoteFetchConfigManagementService method handleRemoteFetchConfigurationException.
/**
* This method is used to handle remote fetch core exception and create API error wit suitable response code and
* status by checking its instance type.
*
* @param e RemoteFetchCoreException.
* @param errorEnum RemoteFetchConfigurationConstants.ErrorMessage
* @param data data
* @return APIError
*/
private APIError handleRemoteFetchConfigurationException(RemoteFetchCoreException e, RemoteFetchConfigurationConstants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof RemoteFetchClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(RemoteFetchConfigurationConstants.ERROR_CODE_DELIMITER) ? errorCode : RemoteFetchConfigurationConstants.REMOTE_FETCH_CONFIGURATION_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof RemoteFetchServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(RemoteFetchConfigurationConstants.ERROR_CODE_DELIMITER) ? errorCode : RemoteFetchConfigurationConstants.REMOTE_FETCH_CONFIGURATION_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
Aggregations