SbuTils 0.1.3

dotnet add package SbuTils --version 0.1.3
                    
NuGet\Install-Package SbuTils -Version 0.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SbuTils" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SbuTils" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="SbuTils" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SbuTils --version 0.1.3
                    
#r "nuget: SbuTils, 0.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=SbuTils&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=SbuTils&version=0.1.3
                    
Install as a Cake Tool

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.

  1. 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
    /* ... */
}

  1. Create a project "umbrella" exception e.g. MyMainException that inherits Exception and could be inherited itself if needed. This exception must implement IHaveErrorCode returning the enum value which can be resolved generically from this exception.

  2. 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.

  1. 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
    /* ... */
}

  1. Whenever a service you create should not throw but could fail, make it return Error<ErrorCodeEnum> or Error<ExpectedReturnedType, ErrorCodeEnum> and give the "throw exception" responsibility to the caller.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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