ApricotFramework.ErrorDefinitions.AspNetCore 0.1.0

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

ApricotFramework.ErrorDefinitions

NuGet NuGet CI License

One error contract for a fleet of services: throw a classified error anywhere, and every service and client reads the same RFC 9457 problem document back — including when the peer is not one of yours.

ApricotFramework.ErrorDefinitions is the zero-dependency core.

Install

dotnet add package ApricotFramework.ErrorDefinitions
dotnet add package ApricotFramework.ErrorDefinitions.AspNetCore

Usage

using ApricotFramework.ErrorDefinitions.AspNetCore.Extensions;

builder.Services.AddErrorDefinitions();      // nothing to configure
app.UseExceptionHandler();
// Throwing: the kind decides the status, the code decides the text a client shows.
var author = Ensure.Found(await repository.Get(id), ContentErrors.AuthorNotFound);

throw Err.Validation(ContentErrors.InvalidLocale, payload: new Dictionary<string, object?>
{
    ["locale"] = locale,          // the client renders its own message from the code and these
}).AsException();

// Reporting several at once, so a caller fixing a form submits it once.
new ErrorCollector()
    .AddIf(string.IsNullOrWhiteSpace(input.Name), Err.Validation(ContentErrors.InvalidName))
    .AddIf(!input.Email.Contains('@'), Err.Validation(ContentErrors.InvalidEmail))
    .ThrowIfAny();
// What the caller receives — application/problem+json
{
  "type": "about:blank",
  "title": "Validation failed",
  "status": 400,
  "detail": "That locale is not published.",
  "instance": "/api/content",
  "errors": [
    { "kind": "validation", "code": "CONTENT_INVALID_LOCALE",
      "message": "That locale is not published.", "payload": { "locale": "fr" } }
  ]
}
// Reading another service's failure, from the zero-dependency core.
using var response = await client.GetAsync(uri, cancellationToken);

await response.EnsureNoErrorsAsync(cancellationToken);   // rethrows the peer's kind and code as your own

An unmapped exception never reaches the caller: it is reported as internal with no message, no exception type and no stack trace, because that text routinely holds connection strings and SQL. The exception goes to the log at error level instead, and that log is the only record of it — the framework's own middleware does not log an exception once a handler has answered it.

The sixteen kinds are google.rpc.Code under names that read better over HTTP, so the same classification maps to gRPC without a second table. schemas/ publishes the whole contract as JSON for clients that are not .NET.

Full documentation: https://projectapricot.dev

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 (4)

Showing the top 4 NuGet packages that depend on ApricotFramework.ErrorDefinitions.AspNetCore:

Package Downloads
ApricotFramework.Captcha.ErrorDefinitions

Reports ApricotFramework.Captcha failures as RFC 9457 problem+json: an exception mapper that turns a rejected or unverifiable captcha into a classified error carrying the rejection reason, so a client can tell an expired challenge from a low score.

ApricotFramework.Authentication.ErrorDefinitions

Reports ApricotFramework.Authentication failures as RFC 9457 problem+json, including the bearer challenge and the authorization forbid that are not exceptions and so escape an exception handler, and classifies a failed service-to-service token as a fault of this service rather than of its caller.

ApricotFramework.Grpc.Server

Answers a failed gRPC call with classified errors, asking the same exception mappers that already answer this service's HTTP requests, so a failure means the same thing whichever way a caller reached it.

ApricotFramework.AccessAuthorization.ErrorDefinitions

Error definition mapping for ApricotFramework.AccessAuthorization: renders authorization failures as RFC 9457 problem details through ApricotFramework.ErrorDefinitions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 229 8/15/2026