Franz.Common.Errors
1.2.62
dotnet add package Franz.Common.Errors --version 1.2.62
NuGet\Install-Package Franz.Common.Errors -Version 1.2.62
<PackageReference Include="Franz.Common.Errors" Version="1.2.62" />
paket add Franz.Common.Errors --version 1.2.62
#r "nuget: Franz.Common.Errors, 1.2.62"
// Install Franz.Common.Errors as a Cake Addin #addin nuget:?package=Franz.Common.Errors&version=1.2.62 // Install Franz.Common.Errors as a Cake Tool #tool nuget:?package=Franz.Common.Errors&version=1.2.62
Franz.Common.Errors
A library for handling and standardizing errors and exceptions in .NET applications. This library simplifies error management, making it easier to implement structured and meaningful error responses.
Features
- Custom Exceptions:
ForbiddenException
FunctionalException
NotFoundException
PreconditionFailedException
TechnicalException
UnauthorizedException
- Base Exception:
ExceptionBase
for creating custom exceptions with consistent behavior.
- Error Response:
ErrorResponse
for structuring API error responses.
Installation
Install the package using NuGet Package Manager or the .NET CLI:
dotnet add package Franz.Common.Errors
Usage
1. Handling Custom Exceptions
Each exception is tailored for specific error scenarios. Here's an example of using NotFoundException
:
using Franz.Common.Errors;
public void FindResource(int id)
{
var resource = GetResourceById(id);
if (resource == null)
{
throw new NotFoundException($"Resource with ID {id} was not found.");
}
}
2. Returning Structured Error Responses
Use ErrorResponse
to provide consistent error information in your APIs:
using Franz.Common.Errors;
public IActionResult HandleException(Exception ex)
{
var errorResponse = new ErrorResponse
{
StatusCode = 500,
Message = ex.Message,
Details = "Additional details about the error."
};
return StatusCode(errorResponse.StatusCode, errorResponse);
}
3. Creating Custom Exceptions
Extend the ExceptionBase
class to create your own exceptions with additional metadata:
using Franz.Common.Errors;
public class CustomException : ExceptionBase
{
public CustomException(string message) : base(message) { }
}
Exception Types Overview
Exception Type | Description |
---|---|
ForbiddenException |
Use for actions the user is not permitted to perform. |
FunctionalException |
Represents a domain or business logic error. |
NotFoundException |
Indicates that a requested resource could not be found. |
PreconditionFailedException |
Indicates a failed precondition for the request. |
TechnicalException |
Represents an unexpected technical error. |
UnauthorizedException |
Indicates a lack of authorization to access a resource. |
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request for review.
License
This library is licensed under the MIT License. See the LICENSE file for more details.
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. |
-
net8.0
- No dependencies.
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Franz.Common.Errors:
Package | Downloads |
---|---|
Franz.Common.Business
Shared utility library for the Franz Framework. |
|
Franz.Common.Reflection
Shared utility library for the Franz Framework. |
|
Franz.Common.Messaging
Shared utility library for the Franz Framework. |
|
Franz.Common.EntityFramework
Shared utility library for the Franz Framework. |
|
Franz.Common.Http.Client
Shared utility library for the Franz Framework. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.62 | 133 | 1/8/2025 |