SbuTils 0.1.3
dotnet add package SbuTils --version 0.1.3
NuGet\Install-Package SbuTils -Version 0.1.3
<PackageReference Include="SbuTils" Version="0.1.3" />
<PackageVersion Include="SbuTils" Version="0.1.3" />
<PackageReference Include="SbuTils" />
paket add SbuTils --version 0.1.3
#r "nuget: SbuTils, 0.1.3"
#addin nuget:?package=SbuTils&version=0.1.3
#tool nuget:?package=SbuTils&version=0.1.3
SbuTils
Nuget package: https://www.nuget.org/packages/SbuTils/
Aspnet core catch-all exceptions middleware
Use this middleware in conjonction with domain exception and error codes to streamline the error handling process in a json rest API.
- Create an "error code enum" that will list all exception errors in your app.
public enum ErrorCodeEnum
{
ITEM_NOT_FOUND,
GROUP_ITEM_NOT_FOUND,
ITEM_FILE_NOT_FOUND
/* ... */
}
Create a project "umbrella" exception e.g.
MyMainException
that inheritsException
and could be inherited itself if needed. This exception must implementIHaveErrorCode
returning the enum value which can be resolved generically from this exception.In aspnet core Program.cs, use the Exception middleware like so:
app.UseExceptionMiddleware(
new ExceptionMiddlewareOptions<ErrorCodeEnum, MyMainException>
{
UnhandledErrorEnumValue = ErrorCodeEnum.UNHANDLED,
EnumToStatusCodeMap = new Dictionary<ErrorCodeEnum, HttpStatusCode>
{
// 400s
{ ErrorCodeEnum.ITEM_NOT_FOUND, 404 },
{ ErrorCodeEnum.GROUP_ITEM_NOT_FOUND, 404 },
...
// 500s
{ ErrorCodeEnum.ITEM_FILE_NOT_FOUND, 500 },
...
}
}
);
Result container
Sometimes we don't want a process to throw, we want to give the Exception handling responsibility to the caller.
Result
gives the flexibility for the service returning it to either succeed or fail without throwing.
- If you haven't already, create an "error code enum" that will contain your app's error codes:
public enum ErrorCodeEnum
{
ITEM_NOT_FOUND,
GROUP_ITEM_NOT_FOUND,
ITEM_FILE_NOT_FOUND
/* ... */
}
- Whenever a service you create should not throw but could fail, make it return
Error<ErrorCodeEnum>
orError<ExpectedReturnedType, ErrorCodeEnum>
and give the "throw exception" responsibility to the caller.
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.2.0)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 8.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- MSTest.TestFramework (>= 3.8.3)
- RunProcessAsTask (>= 1.2.4)
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 |
---|---|---|
0.1.3 | 134 | 6/5/2025 |
0.1.2 | 123 | 6/4/2025 |
0.1.1 | 360 | 3/24/2025 |
0.1.0 | 148 | 3/23/2025 |
0.0.18 | 173 | 3/11/2025 |
0.0.17 | 210 | 3/7/2025 |
0.0.16 | 110 | 2/13/2025 |
0.0.15 | 108 | 2/13/2025 |
0.0.14 | 107 | 2/10/2025 |
0.0.13 | 96 | 2/10/2025 |
0.0.12 | 103 | 2/10/2025 |
0.0.11 | 170 | 10/3/2024 |
0.0.10 | 121 | 10/3/2024 |
0.0.9 | 105 | 10/3/2024 |
0.0.8 | 123 | 10/2/2024 |
0.0.7 | 129 | 10/2/2024 |
0.0.6 | 129 | 10/2/2024 |
0.0.5 | 115 | 10/2/2024 |
0.0.4 | 121 | 10/1/2024 |
0.0.3 | 120 | 10/1/2024 |
0.0.2 | 110 | 10/1/2024 |
0.0.1 | 110 | 10/1/2024 |