ErrorHound 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ErrorHound --version 0.1.0
                    
NuGet\Install-Package ErrorHound -Version 0.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="ErrorHound" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ErrorHound" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ErrorHound" />
                    
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 ErrorHound --version 0.1.0
                    
#r "nuget: ErrorHound, 0.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 ErrorHound@0.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=ErrorHound&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ErrorHound&version=0.1.0
                    
Install as a Cake Tool

ErrorHound

ErrorHound is a lightweight, configurable ASP.NET Core middleware for consistent API error handling. It standardizes error responses, supports built-in common errors, and allows custom response wrappers.


Features

  • Built-in API errors (BadRequestError, NotFoundError, InternalServerError, etc.)
  • Field-level validation errors with ValidationError
  • Minimal API and classic ASP.NET Core support
  • Optional custom response wrapper for full flexibility
  • Automatic logging of all errors

Installation

# Using NuGet
dotnet add package ErrorHound

Usage

Minimal APIs (WebApplication)

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

// Use ErrorHound middleware
app.UseErrorHound(options =>
{
    options.ResponseWrapper = (error) => new
    {
        code = error.Code,
        message = error.Message,
        status = error.Status
    };
});

app.MapGet("/", () =>
{
    throw new NotFoundError("The resource could not be found");
});

app.Run();

Classic ASP.NET Core (IApplicationBuilder)

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseErrorHound(); // optional: pass configuration

    app.UseRouting();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });
}

Built-in Errors

Error HTTP Status Code Message
BadRequestError 400 BAD_REQUEST "The request was invalid or malformed."
ConflictError 409 CONFLICT "The request could not be completed due to a conflict."
DatabaseError 500 DATABASE "A server error occurred while accessing the database."
ForbiddenError 403 FORBIDDEN "You do not have permission to access this resource."
InternalServerError 500 INTERNAL_SERVER "An unexpected internal server error occurred."
NotFoundError 404 NOT_FOUND "The requested resource could not be found."
ServiceUnavailableError 503 SERVICE_UNAVAILABLE "The service is unavailable."
TimeoutError 504 TIMEOUT "The request timed out while processing."
TooManyRequestsError 429 TOO_MANY_REQUESTS "Too many requests have been made. Please try again later."
UnauthorizedError 401 UNAUTHORIZED "Authentication is required to access this resource."
ValidationError 400 VALIDATION "Validation failed" (supports multiple field errors)

Validation Errors

ValidationError supports multiple errors per field:

var validation = new ValidationError();
validation.AddFieldError("Email", "Email is required");
validation.AddFieldError("Email", "Email must be valid");
validation.AddFieldError("Password", "Password is required");

throw validation;

Response example:

{
    "code": "VALIDATION",
    "message": "Validation failed",
    "status": 400,
    "details": {
        "Email": ["Email is required", "Email must be valid"],
        "Password": ["Password is required"]
    }
}

Custom Response Wrapper

You can fully control the shape of error responses:

app.UseErrorHound(options =>
{
    options.ResponseWrapper = (error) => new
    {
        customCode = error.Code,
        customMessage = $"Oops! {error.Message}",
        timestamp = DateTime.UtcNow
    };
});

Testing

  • All built-in errors and ValidationError are fully tested.

  • Middleware behavior is covered for:

    • Standard built-in errors
    • Validation errors
    • Unhandled exceptions
    • Custom response wrapper

Run tests using xUnit:

dotnet test

Logging

ErrorHound logs automatically using ILogger:

  • ValidationErrorLogWarning
  • ApiErrorLogError
  • Other unhandled exceptions → LogCritical

Contributing

  • Fork the repo, make changes, and submit a PR.
  • Tests are written in xUnit; run via dotnet test.
  • Ensure any new built-in errors or middleware behavior are fully tested.

License

MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ErrorHound:

Package Downloads
Pawthorize

Modern authentication library for ASP.NET Core - simple, secure, and opinionated. Email-based authentication with JWT tokens, OAuth 2.0 social login (Google, Discord) with structured name support, refresh token rotation, CSRF protection, password reset, email verification, and enhanced session management with device tracking. Enforces best practices with separated FirstName/LastName fields.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 512 12/28/2025
1.0.0 206 12/23/2025
0.2.0 249 12/14/2025
0.1.0 185 12/14/2025