in Common/ApiWrappers/BaseBatchApiWrapper.cs [71:128]
private void HandleBatchResponses(
IList<(int SourceId, WitBatchRequest WitBatchRequest)> sourceIdToWitBatchRequests,
IList<WitBatchResponse> witBatchResponses,
IMigrationContext migrationContext,
IBatchMigrationContext batchContext)
{
int statusCode = 200;
// For some reason we got a witbatchresponse null or empty - could be due to http errors.
if (ApiWrapperHelpers.ResponsesLackExpectedData(witBatchResponses, sourceIdToWitBatchRequests))
{
Logger.LogInformation(LogDestination.File, $"WitBatchResponses contains no responses. Marking all the work items in batch {batchContext.BatchId} as NotMigrated");
ApiWrapperHelpers.MarkBatchAsFailed(batchContext, sourceIdToWitBatchRequests.Select(r => r.SourceId), FailureReason.CriticalError);
statusCode = 500;
}
// Check if we got one response for the entire batch. This can happen in case of status code 400 - critical error
else if (witBatchResponses.Count == 1 && sourceIdToWitBatchRequests.Count > 1)
{
ApiWrapperHelpers.HandleCriticalError(witBatchResponses.First(), sourceIdToWitBatchRequests.Select(r => r.SourceId), batchContext);
statusCode = 500;
}
// All is good, we got the expected number of responses, process accordingly
else
{
for (int i = 0; i < witBatchResponses.Count; i++)
{
int sourceId = sourceIdToWitBatchRequests[i].SourceId;
int statusCodeForWorkItem = witBatchResponses[i].Code;
if (statusCodeForWorkItem != 200)
{
statusCode = statusCodeForWorkItem;
}
switch ((HttpStatusCode)statusCodeForWorkItem)
{
case HttpStatusCode.OK:
WorkItem workItem = witBatchResponses[i].ParseBody<WorkItem>();
UpdateWorkItemMigrationStatus(batchContext, sourceId, workItem);
break;
case HttpStatusCode.BadRequest:
SaveFailureStatusInWorkItemsMigrationState(batchContext, sourceId, FailureReason.BadRequest);
ApiWrapperHelpers.HandleUnsuccessfulWitBatchResponse(witBatchResponses[i], sourceIdToWitBatchRequests[i], batchContext, statusCodeForWorkItem, FailureReason.BadRequest);
break;
default:
SaveFailureStatusInWorkItemsMigrationState(batchContext, sourceId, FailureReason.UnexpectedError);
ApiWrapperHelpers.HandleUnsuccessfulWitBatchResponse(witBatchResponses[i], sourceIdToWitBatchRequests[i], batchContext, statusCodeForWorkItem, FailureReason.UnexpectedError);
break;
}
}
BatchCompleted(migrationContext, batchContext);
}
if (statusCode != 200)
{
WitBatchRequestLogger.Log(sourceIdToWitBatchRequests.Select(r => r.WitBatchRequest).ToList(), witBatchResponses, batchContext.BatchId);
}
}