Skip to content

Commit

Permalink
update truncation logic, error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Dec 23, 2024
1 parent ff6a6b5 commit 4981bca
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions source/backend/api/Services/DocumentQueueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public async Task<PimsDocumentQueue> Upload(PimsDocumentQueue documentQueue)
databaseDocumentQueue.DocumentQueueStatusTypeCode,
response.DocumentExternalResponse.Status);

databaseDocumentQueue.MayanError = $"Failed to upload document, mayan error: {response.DocumentExternalResponse.Message}".Truncate(4000);
databaseDocumentQueue.MayanError = $"Failed to upload document, mayan error: {response.DocumentExternalResponse.Message}";
UpdateDocumentQueueStatus(databaseDocumentQueue, DocumentQueueStatusTypes.MAYAN_ERROR);
return databaseDocumentQueue;
}
Expand All @@ -267,7 +267,7 @@ public async Task<PimsDocumentQueue> Upload(PimsDocumentQueue documentQueue)
catch (Exception ex) when (ex is BadRequestException || ex is KeyNotFoundException || ex is InvalidDataException || ex is JsonException)
{
this.Logger.LogError($"Error: {ex.Message}");
databaseDocumentQueue.MayanError = ex.Message.Truncate(4000);
databaseDocumentQueue.MayanError = ex.Message;
UpdateDocumentQueueStatus(databaseDocumentQueue, DocumentQueueStatusTypes.PIMS_ERROR);
}
return databaseDocumentQueue;
Expand Down
5 changes: 3 additions & 2 deletions source/backend/api/Services/DocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public async Task<DocumentUploadResponse> UploadDocumentSync(DocumentUploadReque

public async Task<DocumentUploadResponse> UploadDocumentAsync(DocumentUploadRequest uploadRequest, bool skipExtensionCheck = false)
{
this.Logger.LogInformation("Uploading document, do not wait for mayan processing.");
this.Logger.LogInformation("Uploading document, do not wait for mayan processing. documentId: {documentId}", uploadRequest.DocumentId);
this.User.ThrowIfNotAuthorized(Permissions.DocumentAdd);

ExternalResponse<DocumentDetailModel> externalResponse = await UploadDocumentAsync(uploadRequest.DocumentTypeMayanId, uploadRequest.File, skipExtensionCheck);
Expand All @@ -232,7 +232,8 @@ public async Task<DocumentUploadResponse> UploadDocumentAsync(DocumentUploadRequ
}
else
{
this.Logger.LogError("Failed to update associated PIMS document with uploaded Mayan Id.");
this.Logger.LogError("Failed to update associated PIMS document with uploaded Mayan Id. documentId: {documentId}", uploadRequest.DocumentId);
this.Logger.LogDebug("Mayan response: {response}", response.Serialize());
}

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public class DocumentQueueModel : BaseAuditModel
/// </summary>
public string MayanError { get; set; }

/// <summary>
/// get/set - The actual document, represented as a byte[].
/// </summary>
public byte[] Document { get; set; }

/// <summary>
/// get/set - The actual document, represented as a byte[].
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion source/backend/scheduler/Services/DocumentQueueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private DocumentQueueResponseModel HandleDocumentQueueResponse(string httpMethod
var currentDocumentQueue = currentDocumentResponse.Result.Payload;
_logger.LogError("Received error response from {httpMethodName} for queued document {documentQueueId} status {Status} message: {Message}", httpMethodName, currentDocumentQueue?.Id, response?.Result?.Status, response?.Result?.Message);
currentDocumentQueue.DocumentQueueStatusType.Id = DocumentQueueStatusTypes.PIMS_ERROR.ToString();
currentDocumentQueue.MayanError = $"Document {httpMethodName} failed: {response?.Result?.Message}".Truncate(4000);
currentDocumentQueue.MayanError = $"Document {httpMethodName} failed: {response?.Result?.Message}";
_ = _pimsDocumentQueueRepository.UpdateQueuedDocument(currentDocumentQueue.Id, currentDocumentQueue);
});
return new DocumentQueueResponseModel() { DocumentQueueStatus = DocumentQueueStatusTypes.PIMS_ERROR, Message = $"Received error response from {httpMethodName} for queued document {qd?.Id} status {response?.Result?.Status} message: {response?.Result?.Message}" };
Expand Down

0 comments on commit 4981bca

Please sign in to comment.