CatchAll 1.1.0
dotnet add package CatchAll --version 1.1.0
NuGet\Install-Package CatchAll -Version 1.1.0
<PackageReference Include="CatchAll" Version="1.1.0" />
<PackageVersion Include="CatchAll" Version="1.1.0" />
<PackageReference Include="CatchAll" />
paket add CatchAll --version 1.1.0
#r "nuget: CatchAll, 1.1.0"
#:package CatchAll@1.1.0
#addin nuget:?package=CatchAll&version=1.1.0
#tool nuget:?package=CatchAll&version=1.1.0
CatchAll
Centralize and simplify error handling in ASP.NET Core — result pattern and global exception middleware, configured in minutes.
Stop scattering try/catch blocks and HTTP status codes across your controllers. CatchAll gives you a clean Result pattern for expected errors and a global middleware for everything else — so your application always responds consistently.
Installation
dotnet add package CatchAll
Getting started
1. Define your errors
Errors are strongly typed and carry their own HTTP status code. Every AppError supports the following fields:
| Field | Type | Description |
|---|---|---|
Name |
string |
Human-readable error name |
StatusCode |
HttpStatusCode |
HTTP status code returned to the client |
Code |
string? |
Optional machine-readable error code (e.g. "USER_NOT_FOUND") |
Detail |
string? |
Optional additional context about the error |
Path |
string? |
Optional path or resource that originated the error |
public sealed record UserNotFoundError()
: AppError(
Name: "User not found",
StatusCode: HttpStatusCode.NotFound,
Code: "USER_NOT_FOUND",
Detail: "No user was found with the provided ID"
);
public sealed record UnauthorizedError()
: AppError(
Name: "Unauthorized",
StatusCode: HttpStatusCode.Unauthorized,
Code: "UNAUTHORIZED"
);
2. Return results from your services
public CatchOne<User> GetUser(int id)
{
var user = _repository.Find(id);
if (user is null) return new UserNotFoundError();
return user;
}
No exceptions for expected failures. Either you get a User, or you get an AppError.
3. Resolve in your controllers
// Automatic mapping — success becomes 200 OK, error uses its own StatusCode
return result.Resolve();
// Custom success response — error still maps automatically
return result.Resolve(user => Created($"/users/{user.Id}", user));
4. Handle unexpected exceptions globally
Register the middleware once in Program.cs and all unhandled exceptions are caught and returned as a consistent JSON response — no stack traces leaking to the client.
app.UseCatchAll();
The response body follows this structure:
{
"name": "An unexpected error occurred",
"detail": "Object reference not set to an instance of an object",
"path": "/users/42"
}
Options
app.UseCatchAll(options =>
{
options.IncludeStackTrace = true;
options.IncludeExceptionType = true;
options.OnUnhandledException = ex => logger.LogError(ex, "Unhandled exception");
});
| Option | Type | Description |
|---|---|---|
IncludeStackTrace |
bool |
Appends the full stack trace to the error response. Useful during development, not recommended in production. |
IncludeExceptionType |
bool |
Appends the exception type name (e.g. NullReferenceException) to the error response. |
OnUnhandledException |
Action<Exception> |
Callback invoked before the response is sent — use it to log or react to the exception. |
Why CatchAll?
| Without CatchAll | With CatchAll |
|---|---|
try/catch spread across controllers |
Errors as return values |
| Inconsistent error responses | Uniform JSON error format |
| Manual status code mapping | Status code lives in the error itself |
| Unhandled exceptions crash or leak details | Global middleware catches everything |
Contributing
Contributions are welcome! Feel free to open an issue for bugs or suggestions, or submit a pull request.
Please keep PRs focused — one feature or fix per PR makes reviews much easier.
License
MIT © Bruno Ferreira
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|