Fermion.Domain.Exceptions
1.0.0
dotnet add package Fermion.Domain.Exceptions --version 1.0.0
NuGet\Install-Package Fermion.Domain.Exceptions -Version 1.0.0
<PackageReference Include="Fermion.Domain.Exceptions" Version="1.0.0" />
<PackageVersion Include="Fermion.Domain.Exceptions" Version="1.0.0" />
<PackageReference Include="Fermion.Domain.Exceptions" />
paket add Fermion.Domain.Exceptions --version 1.0.0
#r "nuget: Fermion.Domain.Exceptions, 1.0.0"
#:package Fermion.Domain.Exceptions@1.0.0
#addin nuget:?package=Fermion.Domain.Exceptions&version=1.0.0
#tool nuget:?package=Fermion.Domain.Exceptions&version=1.0.0
Fermion.Domain.Exceptions
Fermion.Exceptions is a library that provides a comprehensive exception handling system for .NET applications. It includes predefined exception types and interfaces for standardized error handling across your application.
Features
- Predefined exception types for common scenarios
- Standardized exception interfaces
- HTTP status code mapping
- Validation error handling
- Business rule violation handling
- Entity not found handling
- User-friendly error messages
- Correlation ID support
Installation
dotnet add package Fermion.Domain.Exceptions
Content
Exception Types
Base Exception
AppException
: Base exception class with common properties and behaviors- Error code
- Error details
- Timestamp
- Correlation ID
Domain Exceptions
AppEntityNotFoundException
: Thrown when an entity is not found- Entity type
- Entity ID
- Search criteria
- Custom message
AppBusinessException
: Thrown when business rules are violated- Business rule code
- Business rule message
- Additional context
AppValidationException
: Thrown when validation fails- Validation errors collection
- Field-specific errors
- Custom validation messages
AppAuthorizationException
: Thrown when authorization fails- Required permissions
- Access denied reason
- User context
AppUserFriendlyException
: Thrown for user-friendly error messages- User-friendly message
- Technical details (optional)
- Suggested actions
Exception Interfaces
Core Interfaces
IHasErrorCode
: Interface for exceptions with error codesIHasErrorDetails
: Interface for exceptions with detailed error informationIHasTimestamp
: Interface for exceptions with timestamp informationIHasCorrelationId
: Interface for exceptions with correlation ID trackingIHasStatusCode
: Interface for exceptions with HTTP status codesIHasValidationErrors
: Interface for exceptions with validation errors
Usage
Basic Exception Usage
// Entity not found
throw new AppEntityNotFoundException(typeof(User), userId);
// Business rule violation
throw new AppBusinessException("USER_INACTIVE", "User account is inactive");
// Authorization error
throw new AppAuthorizationException("ADMIN_REQUIRED", "Admin access required");
// User-friendly error
throw new AppUserFriendlyException(
"Unable to process your request at this time",
"Please try again later or contact support"
);
AppException Methods
AppException
provides a fluent API for configuring exception properties:
// Basic usage
throw new AppBusinessException("User account is inactive")
.WithCode("USER:INACTIVE:1001")
.WithDetails("Account was deactivated by admin")
.WithStatusCode(400)
.WithCorrelationId("corr-123")
.WithData("UserId", userId)
.AppendData(new Dictionary<string, object>
{
{ "LastLoginDate", lastLoginDate },
{ "DeactivationReason", reason }
});
Available Methods
WithData(string name, object value)
: Adds a single key-value pair to exception dataAppendData(IDictionary<string, object> data)
: Adds multiple key-value pairs to exception dataWithCode(string code)
: Sets the error codeWithDetails(string details)
: Sets the error detailsWithStatusCode(int statusCode)
: Sets the HTTP status codeWithCorrelationId(string correlationId)
: Sets the correlation ID
Features
- Standardized exception handling
- HTTP status code mapping
- Validation error collection
- Business rule violation handling
- Entity not found handling
- User-friendly messages
- Correlation tracking
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
- No dependencies.
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 |
---|