com.ih.util.custom.errors
1.0.0
dotnet add package com.ih.util.custom.errors --version 1.0.0
NuGet\Install-Package com.ih.util.custom.errors -Version 1.0.0
<PackageReference Include="com.ih.util.custom.errors" Version="1.0.0" />
<PackageVersion Include="com.ih.util.custom.errors" Version="1.0.0" />
<PackageReference Include="com.ih.util.custom.errors" />
paket add com.ih.util.custom.errors --version 1.0.0
#r "nuget: com.ih.util.custom.errors, 1.0.0"
#:package com.ih.util.custom.errors@1.0.0
#addin nuget:?package=com.ih.util.custom.errors&version=1.0.0
#tool nuget:?package=com.ih.util.custom.errors&version=1.0.0
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 | Versions 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. |
-
net7.0
- Microsoft.AspNetCore.Diagnostics.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
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 |
|---|