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
<PackageReference Include="Hrithik.Api.ErrorKit" Version="1.0.0" />
<PackageVersion Include="Hrithik.Api.ErrorKit" Version="1.0.0" />
<PackageReference Include="Hrithik.Api.ErrorKit" />
paket add Hrithik.Api.ErrorKit --version 1.0.0
#r "nuget: Hrithik.Api.ErrorKit, 1.0.0"
#:package Hrithik.Api.ErrorKit@1.0.0
#addin nuget:?package=Hrithik.Api.ErrorKit&version=1.0.0
#tool nuget:?package=Hrithik.Api.ErrorKit&version=1.0.0
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:
- โ Buy Me a Coffee: https://www.buymeacoffee.com/alkylhalid9
- โค๏ธ GitHub Sponsors: https://github.com/sponsors/hrithikalra
Support is entirely optional and helps sustain ongoing development and maintenance.
| Product | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.2)
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 |