Refactor error handling in DocumentService and consumers
Refactored `DocumentService.GetDocumentAsync` to throw `HttpRequestException` on failure instead of returning a tuple. Updated all consumers to handle exceptions, improving error handling consistency across the application. Enhanced error messages for better user feedback and added logging for improved traceability. Updated `EnvelopeReceiverPage`, `EnvelopeReceiverPage_DxReportViewer`, and `ReportViewer` to use the new exception-based API and handle errors gracefully. This change simplifies the API, improves maintainability, and makes the application more robust and user-friendly.
This commit is contained in:
@@ -563,13 +563,13 @@ const int MaxThumbnailWidth = 400;
|
||||
}
|
||||
|
||||
try {
|
||||
var (pdfBytes, statusCode) = await DocumentService.GetDocumentAsync(EnvelopeKey);
|
||||
var pdfBytes = await DocumentService.GetDocumentAsync(EnvelopeKey);
|
||||
|
||||
if (pdfBytes is { Length: > 0 }) {
|
||||
var base64 = Convert.ToBase64String(pdfBytes);
|
||||
_pdfDataUrl = $"data:application/pdf;base64,{base64}";
|
||||
} else {
|
||||
_errorMessage = $"Dokument konnte nicht geladen werden. HTTP Status: {statusCode}";
|
||||
_errorMessage = "Dokument konnte nicht geladen werden: Keine Daten empfangen.";
|
||||
}
|
||||
|
||||
var signatures = await SignatureService.GetAsync(EnvelopeKey);
|
||||
@@ -608,8 +608,12 @@ const int MaxThumbnailWidth = 400;
|
||||
_popupValidationMessage = null;
|
||||
}
|
||||
|
||||
} catch (HttpRequestException ex) {
|
||||
_errorMessage = $"Dokument konnte nicht geladen werden: {ex.Message}";
|
||||
logger.LogError(ex, "Failed to load document for envelope {EnvelopeKey}", EnvelopeKey);
|
||||
} catch (Exception ex) {
|
||||
_errorMessage = $"Fehler: {ex.Message}";
|
||||
logger.LogError(ex, "Unexpected error during initialization for envelope {EnvelopeKey}", EnvelopeKey);
|
||||
}
|
||||
|
||||
_isLoading = false;
|
||||
|
||||
Reference in New Issue
Block a user