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:
@@ -25,11 +25,15 @@
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
if (!AppOptions.Value.UsePredefinedReports) {
|
||||
var (pdfBytes, _) = await DocumentService.GetDocumentAsync(EnvelopeKey);
|
||||
if (pdfBytes is { Length: > 0 })
|
||||
BasePdfBytes = pdfBytes;
|
||||
else
|
||||
throw new InvalidOperationException($"No PDF bytes found for EnvelopeKey: {EnvelopeKey}");
|
||||
try {
|
||||
var pdfBytes = await DocumentService.GetDocumentAsync(EnvelopeKey);
|
||||
if (pdfBytes is { Length: > 0 })
|
||||
BasePdfBytes = pdfBytes;
|
||||
else
|
||||
throw new InvalidOperationException($"No PDF bytes found for EnvelopeKey: {EnvelopeKey}");
|
||||
} catch (HttpRequestException ex) {
|
||||
throw new InvalidOperationException($"Failed to load document for EnvelopeKey: {EnvelopeKey}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
Report = CreateReport();
|
||||
|
||||
Reference in New Issue
Block a user