HttpStatusExceptions 1.0.3

dotnet add package HttpStatusExceptions --version 1.0.3
                    
NuGet\Install-Package HttpStatusExceptions -Version 1.0.3
                    
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="HttpStatusExceptions" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HttpStatusExceptions" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="HttpStatusExceptions" />
                    
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 HttpStatusExceptions --version 1.0.3
                    
#r "nuget: HttpStatusExceptions, 1.0.3"
                    
#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 HttpStatusExceptions@1.0.3
                    
#: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=HttpStatusExceptions&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=HttpStatusExceptions&version=1.0.3
                    
Install as a Cake Tool

HttpStatusExceptions

HttpStatusExceptions HttpStatusExceptions.AspNetCore License

A lightweight library for throwing HTTP status code exceptions using clean, expressive static helper methods.

Installation

# Base library
dotnet add package HttpStatusExceptions

# ASP.NET Core integration (includes ProblemDetails support)
dotnet add package HttpStatusExceptions.AspNetCore

Usage

Throwing Exceptions

using HttpStatusExceptions;

// Using static throw helpers
HttpStatusException.Throw404NotFound();
HttpStatusException.Throw401Unauthorized("Invalid API key.");

// Or throw directly
throw new HttpStatusException(404, "Resource not found.");

Generic Variants

Generic overloads let you throw in expression contexts—useful for null-coalescing and conditional expressions:

var item = await db.Items.FirstOrDefaultAsync(item => item.Id == id)
    ?? HttpStatusException.Throw404NotFound<Item>("Item not found.");

var result = isValid
    ? ProcessData()
    : HttpStatusException.Throw400BadRequest<Result>();

ProblemDetails Support (ASP.NET Core)

The HttpStatusExceptions.AspNetCore package adds a ToProblemDetails() extension method:

using HttpStatusExceptions.AspNetCore;

// In Program.cs
builder.Services.AddProblemDetails(options =>
{
    options.CustomizeProblemDetails = (ctx) =>
    {
        ctx.ProblemDetails = MapProblemDetails(ctx.Exception);
    };
});

static ProblemDetails MapProblemDetails(Exception? ex)
    => ex switch
    {
        HttpStatusException httpEx => httpEx.ToProblemDetails(),
        _ => new ProblemDetails
        {
            Detail = "An unexpected error occurred.",
            Status = StatusCodes.Status500InternalServerError,
        }
    };

Supported Status Codes

All standard 4xx and 5xx status codes are supported:

Category Status Codes
4xx Client Errors 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 426, 428, 429, 431, 451
5xx Server Errors 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511

Additionally, 405 Method Not Allowed has method-specific helpers: Throw405GetNotAllowed(), Throw405PostNotAllowed(), Throw405PutNotAllowed(), Throw405DeleteNotAllowed(), etc.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on HttpStatusExceptions:

Package Downloads
HttpStatusExceptions.AspNetCore

A lightweight library for throwing HTTP status code exceptions using clean, expressive static helper methods. Additionally contains `ProblemDetails` support for ASP.NET Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 37 3/6/2026
1.0.2 117 1/15/2026
1.0.1 108 1/15/2026
1.0.0 112 1/15/2026