Persilsoft.Exceptions
1.0.14
dotnet add package Persilsoft.Exceptions --version 1.0.14
NuGet\Install-Package Persilsoft.Exceptions -Version 1.0.14
<PackageReference Include="Persilsoft.Exceptions" Version="1.0.14" />
paket add Persilsoft.Exceptions --version 1.0.14
#r "nuget: Persilsoft.Exceptions, 1.0.14"
// Install Persilsoft.Exceptions as a Cake Addin #addin nuget:?package=Persilsoft.Exceptions&version=1.0.14 // Install Persilsoft.Exceptions as a Cake Tool #tool nuget:?package=Persilsoft.Exceptions&version=1.0.14
Persilsoft.Exceptions
It contains custom exceptions with their respective handlers. These handlers implement the new AspNet Core 8.0 interface IExceptionHandler, formatting the output into a ProblemDetails object serialized to Json.
The package contains the following exceptions:
- ForbiddenAccessException
- NotFoundException
- UpdateException
- ValidationException
The respective handlers for each of the exceptions are registered as follows:
builder.Services
.AddNotFoundExceptionHandler()
.AddValidationExceptionHandler()
.AddUpdateExceptionHandler()
.AddUnhandledExceptionHandler();
The title of the ProblemDetails can be displayed in either English or Spanish. To achieve this, you need to configure localization middleware in your AspNet Core application:
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[] { "en-US", "es-PE" };
var neutralCulture = supportedCultures[0];
options.SetDefaultCulture(neutralCulture)
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);
});
Finally, we add the localization and exception handling middlewares to the AspNet Core pipeline
app.UseRequestLocalization();
app.UseExceptionHandler(e => { });
Note:
It's important that the localization middleware is added before the exception handling middleware; otherwise, you won't see the messages in the appropriate language.
Example
app.MapGet("/admin/dashboard", () =>
{
throw new ForbiddenAccessException();
})
.WithName("Admin");
app.MapGet("/product/{id:int}", async (int id, MyContext context) =>
{
var Product = await context.Products.SingleOrDefaultAsync(p => p.Id == id);
if (Product is null)
{
throw new NotFoundException();
}
return Results.Ok(Product);
})
.WithTags("Product");
app.MapPost("/Product/register", async (MyContext context) =>
{
context.Add(new Product
{
Id = 7,
Name = "Chai",
UnitPrice = 59.99M,
UnitsInStock = 80
});
try
{
await context.SaveChangesAsync();
}
catch (DbUpdateException ex)
{
throw new UpdateException(ex, ex.Entries.Select(e => e.Entity.GetType().Name));
}
return Results.Ok("Product registered.");
})
.WithTags("Product");
You can see an example of ValidationException in the package documentation Persilsoft.Validation
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. |
-
net8.0
- Persilsoft.Localizer (= 1.0.7)
- Persilsoft.Validation (= 1.0.9)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Persilsoft.Exceptions:
Package | Downloads |
---|---|
Persilsoft.Recaptcha.Server
Exposes an endpoint to interact with the Google API to validate a reCAPTCHA V3 token. |
|
Persilsoft.Sms.Abstractions
Contains an interface to be used in an SMS-sending project |
|
Persilsoft.Culqi.Server
Expone algunos endpoints para interactuar con la API de Culqi durante el proceso de Checkout. |
|
Persilsoft.Mail.MailKit.Sender
An implementation of MailKit (a popular Mail library) |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.14 | 464 | 1/12/2025 |
1.0.13 | 36 | 1/12/2025 |
1.0.12 | 40 | 1/10/2025 |
1.0.11 | 480 | 10/16/2024 |
1.0.10 | 1,260 | 7/20/2024 |
1.0.9 | 1,130 | 5/25/2024 |
1.0.8 | 232 | 5/22/2024 |
1.0.7 | 235 | 5/21/2024 |
1.0.6 | 713 | 5/4/2024 |
1.0.5 | 294 | 4/28/2024 |
1.0.4 | 126 | 4/28/2024 |
1.0.3 | 409 | 4/27/2024 |
1.0.2 | 383 | 4/14/2024 |
1.0.1 | 136 | 4/12/2024 |
1.0.0 | 118 | 4/12/2024 |