com-ih-util-custom-errors 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package com-ih-util-custom-errors --version 1.0.0
                    
NuGet\Install-Package com-ih-util-custom-errors -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="com-ih-util-custom-errors" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="com-ih-util-custom-errors" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="com-ih-util-custom-errors" />
                    
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 com-ih-util-custom-errors --version 1.0.0
                    
#r "nuget: com-ih-util-custom-errors, 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.
#:package com-ih-util-custom-errors@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=com-ih-util-custom-errors&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=com-ih-util-custom-errors&version=1.0.0
                    
Install as a Cake Tool

Repository: https://github.com/ih-sw/com-ih-util-custom-errors


CUSTOM ERROR EXCEPTION

Library for using custom Exceptions, where it is possible to obtain a response for the application containing only messages and basic information, and for the LOG complete messages and TRACES.

Your Exception class should extend the 'CustomErrorException' class:

public class AppAuthenticationExpiredSessionCustomErrorException : CustomErrorException
{
	public override string message { get { return "Expired Session"; } }
	public override string code { get { return "authentication-expired-session"; } }
	public override int status { get { return StatusCodes.Status401Unauthorized; } }

	public AppAuthenticationExpiredSessionCustomErrorException(string contentBodyRequest = null, string contentBodyResponse = null, Dictionary<string, string> details = null)
	{
		this.contentBodyRequest = contentBodyRequest;
		this.contentBodyResponse = contentBodyResponse;
	}
}

Wherever:

[string] message: Message you want to expose.
[string] code: Unique code for tracking or error handling.
[int] status: Error (Status Http) code.
[string] contentBodyRequest: Private information, where it is possible to inform content, such as the request sent to an API where an error was returned.
[string] contentBodyResponse: Private information, where it is possible to inform content, such as an API response that returned an error.
[Dictionary<string, string>] details: Key/value list where you can enter values that are returned in the response.

Information visible in the application response:

[string] message
[string] code
[int] status
[Dictionary<string, string>] details

All information contained in any parameter of the Exception object will be exposed in the TRACE of the LOG.

ErrorService - Error handling control service:

The error handling service is responsible for intercepting the Exceptions thrown by the application, and overwriting them to the above mentioned format.

A configuration must be made in the application's control class (in .NET Core, Program.cs).

.NET Core Application - HANDLER Configuration:

For correct operation, a HANDLER must be configured in the application's main control class.

internal class Program
{
    private static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

		...

        app.UseExceptionHandler(ErrorService.HandleError);
        app.Run();
    }
}

Using a custom Exception class:

Forced

throw new UserLoginUnauthorizedError(contentBodyRequest: "Not enable, status " + user.UserStatus.ToString() + " - Data: " + JsonConvert.SerializeObject(userDto));

Catch

catch (UserLoginError ex)
{
	userDto.AccessPassword = string.Empty;

	ex.contentBodyRequest = "Data: " + JsonConvert.SerializeObject(userDto);

	throw ex;
}

'UserLoginUnauthorizedError' and 'UserLoginError' are extending 'CustomErrorException'.
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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.  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