Skip to content

Commit f066759

Browse files
committed
add a 500
1 parent aad76f7 commit f066759

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

Controllers/DashboardController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ public IActionResult Index()
1414
{
1515
return Inertia.Render("Dashboard/Index");
1616
}
17+
18+
[HttpGet]
19+
[Route("500")]
20+
public IActionResult ThrowException()
21+
{
22+
throw new Exception("Test exception for 500 error page");
23+
}
1724
}
1825
}

Middleware/ExceptionMiddleware.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ private async Task HandleExceptionAsync(HttpContext context, Exception exception
4949
throw exception;
5050
}
5151

52+
// In development, let the exception bubble up for normal .NET error handling
53+
if (_env.IsDevelopment())
54+
{
55+
throw exception;
56+
}
57+
5258
context.Response.StatusCode = 500;
5359

5460
// Clear any existing TempData to prevent serialization issues
@@ -59,12 +65,14 @@ private async Task HandleExceptionAsync(HttpContext context, Exception exception
5965
tempData.Clear();
6066
}
6167

68+
var isDevelopment = _env.IsDevelopment();
69+
6270
var errorData = new
6371
{
64-
message = _env.IsDevelopment()
72+
message = isDevelopment
6573
? exception.Message
6674
: "An unexpected error occurred. Please try again later.",
67-
stackTrace = _env.IsDevelopment() ? exception.StackTrace : null
75+
stackTrace = isDevelopment ? exception.StackTrace : null
6876
};
6977

7078
var result = Inertia.Render("Error/ServerError", errorData);

0 commit comments

Comments
 (0)