CatchAll 1.1.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package CatchAll --version 1.1.0
                    
NuGet\Install-Package CatchAll -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CatchAll" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CatchAll" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="CatchAll" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CatchAll --version 1.1.0
                    
#r "nuget: CatchAll, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CatchAll@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CatchAll&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=CatchAll&version=1.1.0
                    
Install as a Cake Tool

CatchAll

Centralize and simplify error handling in ASP.NET Core — result pattern and global exception middleware, configured in minutes.

NuGet Version NuGet Downloads License: MIT Build

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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