feat: add error handling to job editor and Error page
Wrap job editor initialization in try/catch to display errors instead of crashing the circuit. Make LoadSavedResults async. Add a simple Error page for the production exception handler. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
@page "/Error"
|
||||||
|
|
||||||
|
<PageTitle>Error</PageTitle>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="card border-danger">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<h1 class="text-danger mb-3">Something went wrong</h1>
|
||||||
|
<p class="lead">An unexpected error occurred. Please try again later.</p>
|
||||||
|
<a href="/" class="btn btn-primary mt-3">Return to home page</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -32,7 +32,14 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (loading)
|
@if (!string.IsNullOrEmpty(loadError))
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<h5>Error loading job</h5>
|
||||||
|
<pre class="mb-0">@loadError</pre>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else if (loading)
|
||||||
{
|
{
|
||||||
<p><em>Loading...</em></p>
|
<p><em>Loading...</em></p>
|
||||||
}
|
}
|
||||||
@@ -331,6 +338,7 @@ else
|
|||||||
private List<CuttingTool> cuttingTools = new();
|
private List<CuttingTool> cuttingTools = new();
|
||||||
|
|
||||||
private bool loading = true;
|
private bool loading = true;
|
||||||
|
private string? loadError;
|
||||||
private bool savingJob;
|
private bool savingJob;
|
||||||
private string? jobErrorMessage;
|
private string? jobErrorMessage;
|
||||||
private Tab activeTab = Tab.Details;
|
private Tab activeTab = Tab.Details;
|
||||||
@@ -388,43 +396,50 @@ else
|
|||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
materials = await MaterialService.GetAllAsync();
|
try
|
||||||
cuttingTools = await JobService.GetCuttingToolsAsync();
|
|
||||||
|
|
||||||
if (Id.HasValue)
|
|
||||||
{
|
{
|
||||||
var existing = await JobService.GetByIdAsync(Id.Value);
|
materials = await MaterialService.GetAllAsync();
|
||||||
if (existing == null)
|
cuttingTools = await JobService.GetCuttingToolsAsync();
|
||||||
{
|
|
||||||
Navigation.NavigateTo("jobs");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
job = existing;
|
|
||||||
|
|
||||||
// Load saved optimization results if available
|
if (Id.HasValue)
|
||||||
if (job.OptimizationResultJson != null)
|
|
||||||
{
|
{
|
||||||
LoadSavedResults();
|
var existing = await JobService.GetByIdAsync(Id.Value);
|
||||||
|
if (existing == null)
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("jobs");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
job = existing;
|
||||||
|
|
||||||
|
// Load saved optimization results if available
|
||||||
|
if (job.OptimizationResultJson != null)
|
||||||
|
{
|
||||||
|
await LoadSavedResultsAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Set default cutting tool for new jobs
|
||||||
|
var defaultTool = await JobService.GetDefaultCuttingToolAsync();
|
||||||
|
if (defaultTool != null)
|
||||||
|
{
|
||||||
|
job.CuttingToolId = defaultTool.Id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Set default cutting tool for new jobs
|
loadError = ex.ToString();
|
||||||
var defaultTool = await JobService.GetDefaultCuttingToolAsync();
|
|
||||||
if (defaultTool != null)
|
|
||||||
{
|
|
||||||
job.CuttingToolId = defaultTool.Id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadSavedResults()
|
private async Task LoadSavedResultsAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
packResult = PackingService.LoadSavedResult(job.OptimizationResultJson!);
|
packResult = await PackingService.LoadSavedResultAsync(job.OptimizationResultJson!);
|
||||||
if (packResult != null)
|
if (packResult != null)
|
||||||
{
|
{
|
||||||
summary = PackingService.GetSummary(packResult);
|
summary = PackingService.GetSummary(packResult);
|
||||||
|
|||||||
Reference in New Issue
Block a user