A structured error handling framework for .NET that replaces scattered exception patterns with typed, context-rich errors. Built around RFC 7807 Problem Details, with error codes, context chains, severity levels, global error hooks, a Result pattern for explicit error handling, and an exception bridge for boundary crossing.
- Typed Errors — Define application-specific error types with codes, severity, and metadata
- Context Chains — Wrap errors with additional context as they propagate up the call stack
- RFC 7807 Problem Details — Automatic serialization to standard Problem Details JSON for API responses
- Error Codes — Centralized error code registry with documentation URLs and categorization
- Severity Levels — Classify errors as Info, Warning, Error, Critical, or Fatal
- Global Hooks — Register error handlers that fire on any error (logging, telemetry, alerting)
- Result Pattern —
Result<T>type for explicit error handling without exceptions - Exception Bridge — Convert between typed errors and exceptions when crossing boundaries
dotnet add package JG.ErrorKit// Define application errors
public class UserErrors : ErrorCategory
{
public static readonly ErrorCode NotFound = new("USER_001", "User not found");
public static readonly ErrorCode InvalidEmail = new("USER_002", "Invalid email format");
}
// Return typed results
public Result<User> GetUser(string id)
{
var user = _repo.Find(id);
if (user is null)
return AppError.From(UserErrors.NotFound).WithContext("id", id);
return user;
}- Define error codes and register them with
services.AddErrorKit(...). - Return typed results for predictable error handling.
- Publish errors to observers for logging or telemetry.
- Map to RFC 7807 Problem Details when returning API responses.
See Getting Started for full walkthroughs.
- API Reference — Full API documentation and examples
- Getting Started — Setup guide and common workflows
Contributions are welcome! Please feel free to submit a Pull Request.
Licensed under the Apache License 2.0. See LICENSE for details.
Ready to get started? Install via NuGet and check out the API reference.