Refactor UpsertAsync to use ApiResult for error handling
MassDataApiClient.UpsertAsync now returns ApiResult to standardize success and error reporting, including detailed error extraction from API responses. Updated MassDataGrid.razor to handle the new result type and display error messages accordingly. Removed obsolete try-catch logic in favor of the new pattern.
This commit is contained in:
@@ -305,18 +305,17 @@ else
|
||||
Category = editModel.Category,
|
||||
StatusFlag = editModel.StatusFlag
|
||||
};
|
||||
try
|
||||
|
||||
var result = await Api.UpsertAsync(dto);
|
||||
if (!result.Success)
|
||||
{
|
||||
var saved = await Api.UpsertAsync(dto);
|
||||
infoMessage = editModel.IsNew ? "MassData angelegt." : "MassData aktualisiert.";
|
||||
focusedRowKey = saved.Id;
|
||||
await LoadPage(pageIndex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = $"Fehler beim Speichern: {ex.Message}";
|
||||
errorMessage = result.Error ?? "Speichern fehlgeschlagen.";
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
infoMessage = editModel.IsNew ? "MassData angelegt." : "MassData aktualisiert.";
|
||||
focusedRowKey = result.Value?.Id;
|
||||
await LoadPage(pageIndex);
|
||||
}
|
||||
|
||||
private void AddValidationError(MassDataEditModel editModel, string fieldName, string message)
|
||||
|
||||
Reference in New Issue
Block a user