Hrithik.Api.ErrorKit 1.0.0

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

Hrithik.Api.ErrorKit

A lightweight, opinionated API error standardization library for ASP.NET Core

Hrithik.Api.ErrorKit provides a single, frontend-friendly error contract for all API failures โ€” validation errors, domain errors, security failures, and unexpected exceptions.

โœจ Why ApiErrorKit?

Most APIs suffer from:

Inconsistent error responses

Ad-hoc exception handling

Frontend teams guessing error formats

Mixed ProblemDetails, anonymous objects, and stack traces

ApiErrorKit fixes this by enforcing one error shape everywhere.

๐ŸŽฏ Goals

One consistent JSON error format

Frontend-friendly (easy to map to UI)

Secure (no stack traces or internal details)

Minimal configuration

Works with Minimal APIs & MVC

Designed for real production systems

๐Ÿ“ฆ Installation dotnet add package Hrithik.Api.ErrorKit

๐Ÿš€ Quick Start 1๏ธโƒฃ Register services builder.Services.AddApiErrorKit();

2๏ธโƒฃ Add middleware app.UseApiErrorKit();

โš ๏ธ UseApiErrorKit() must be the only global error formatter.

๐Ÿงพ Standard Error Response { "type": "https://errors.hrithik.dev/api-error", "title": "Request Failed", "status": 400, "code": "VALIDATION_ERROR", "message": "One or more validation errors occurred.", "errors": { "email": ["Email is required"] }, "traceId": "0HNJ4NEBC5DKD:00000003", "timestamp": "2026-02-05T13:43:09.680091Z", "subErrors": [] }

๐Ÿงฉ Core Concepts ApiException

All client-visible errors must derive from ApiException.

throw new NotFoundException("User not found");

ApiErrorKit automatically converts this into a standardized JSON response.

Validation Errors throw new ValidationException(new Dictionary<string, string[]> { ["email"] = new[] { "Email is required" } });

Produces a structured errors object ideal for forms.

Unknown Errors

Any unhandled or unknown exception is safely converted to:

{ "code": "INTERNAL_ERROR", "status": 500, "message": "An unexpected error occurred." }

๐Ÿ›‘ Important Design Rule

ApiErrorKit formats errors. It does NOT decide what errors clients should see.

Infrastructure or security libraries should throw their own exceptions. Your API should translate them into ApiException at the boundary.

๐Ÿ” Translating Infrastructure Exceptions (Example) catch (SecurityException ex) { throw new InvalidSecurityHeadersException(ex.Message); }

This keeps:

Security libraries independent

ApiErrorKit reusable

API behavior explicit

๐Ÿง  Architecture Overview [ Infrastructure Libraries ] โ”œโ”€ Security / Idempotency / Rate Limiting โ””โ”€ throw infra exceptions

[ API Boundary ] โ”œโ”€ Translate infra โ†’ ApiException โ””โ”€ Audit / policy decisions

[ ApiErrorKit ] โ””โ”€ Formats ApiException โ†’ JSON

๐Ÿงช Testing

ApiErrorKit is best tested via:

Integration tests

Demo API projects

Real security & validation failures

Example assertion:

response.StatusCode.Should().Be(HttpStatusCode.Conflict); json.Should().Contain("IDEMPOTENCY_KEY_REUSE");

๐Ÿ“Œ What ApiErrorKit Does NOT Do

โŒ Does not log errors

โŒ Does not decide HTTP status codes

โŒ Does not replace business logic

โŒ Does not couple to security libraries

๐Ÿ”œ Roadmap

FluentValidation integration

OpenAPI / Swagger error schemas

Localization support

TypeScript client generation

Error code registry

๐Ÿค Contributing

Contributions are welcome:

Bug fixes

Documentation improvements

Tests

Feature discussions

Please open an issue before submitting major changes.

๐Ÿ“œ License

MIT License

๐Ÿ‘ค Author

Hrithik Kalra

.NET | API Security | Fintech Systems

๐Ÿ“ง Email: hrithikkalra11@gmail.com

GitHub: https://github.com/hrithikalra

LinkedIn: https://www.linkedin.com/in/hrithik-kalra-b6836a246/

If you find this package useful, consider supporting its development:

Support is entirely optional and helps sustain ongoing development and maintenance.


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.

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
1.0.0 131 2/5/2026