Errorist 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Errorist --version 1.0.0
NuGet\Install-Package Errorist -Version 1.0.0
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="Errorist" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Errorist --version 1.0.0
#r "nuget: Errorist, 1.0.0"
#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.
// Install Errorist as a Cake Addin
#addin nuget:?package=Errorist&version=1.0.0

// Install Errorist as a Cake Tool
#tool nuget:?package=Errorist&version=1.0.0

Errorist

A compact and configurable package for formatting API exception output in .NET 6


Errorist allows API developers to quickly configure the way that errors thrown in the application are displayed to the API consumer. Developers can alter output based on the type of exception, the controller or service it was thrown from, or specific attributes of the exception itself. Use the built-in ApiExceptionDto or register your own output models.

Getting started

To use Errorist in your application, assuming that you wish to use the in-built ApiExceptionDto output model, you will first need to add the following code to your Program file:

builder.Services.AddErrorConfiguration<ApiExceptionDto>();

After the builder.Build() method has been called, you will need to add the middleware to the application's pipeline:

app.UseErrorConfigurationMiddleware<ApiExceptionDto>();

Global configurations

Whilst in the Program file, it is recommended that you add some Global configurations - these can then be overridden throughout the application as needed. For this you can use app.UseGlobalDefaultErrorConfiguration<ApiExceptionDto> for all exceptions, or app.UseGlobalErrorConfiguration<ApiExceptionDto,TException> for specific types.

For example, using the built-in generic builder:

app.UseGlobalDefaultErrorConfiguration<ApiExceptionDto>()
    .AddConfiguration((e, dto) => 
    {
        dto.Title = "Something went wrong",
        dto.Message = $"The application threw an exception of type {e.GetType().FullName}",
        dto.UserAdvice = "Please contact your technical team",
        dto.StatusCode = 500
    });
    
app.UseGlobalErrorConfiguration<ApiExceptionDto, AuthenticationException>()
    .AddConfiguration((e, dto) =>
    {
        dto.StatusCode = 401,
        dto.UserAdvice = "Try logging in"
    });

If no further configuration is added beyond these global configurations, most users with an error will receive the following json (or similar) with a status code of 500:

{
    "title": "Something went wrong",
    "message": "The application threw an exception of type System.Exception",
    "userAdvice": "Please contact your technical team"
}

Whereas those experiencing an AuthenticationException will receive the following, with a status code of 401:

{
    "title": "Something went wrong",
    "message": "The application threw an exception of type MyApplication.Exceptions.AuthenticationException",
    "userAdvice": "Try logging in"
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
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
1.0.2 207 3/26/2023
1.0.1 211 2/27/2023
1.0.0 278 2/25/2023