GM.Exceptions
1.2.1
dotnet add package GM.Exceptions --version 1.2.1
NuGet\Install-Package GM.Exceptions -Version 1.2.1
<PackageReference Include="GM.Exceptions" Version="1.2.1" />
<PackageVersion Include="GM.Exceptions" Version="1.2.1" />
<PackageReference Include="GM.Exceptions" />
paket add GM.Exceptions --version 1.2.1
#r "nuget: GM.Exceptions, 1.2.1"
#:package GM.Exceptions@1.2.1
#addin nuget:?package=GM.Exceptions&version=1.2.1
#tool nuget:?package=GM.Exceptions&version=1.2.1
<p align="center"> <img src="https://raw.githubusercontent.com/gmetskhvarishvili/GM.Exceptions/master/icon.png" alt="GM.Exceptions" width="140" height="140" /> </p>
GM.Exceptions
A small collection of reusable exception types for .NET apps: a common base exception,
HTTP-style domain exceptions (not found, bad request, already exists, …), and a
FluentValidation-aware ValidationException. Messages can be localized from .resx
resources. Targets net10.0.
Install
dotnet add package GM.Exceptions
Exception types
| Type | Purpose |
|---|---|
CustomException |
Base type for all the others (derives from Exception). |
NotFoundException |
An entity/relationship wasn't found. |
AlreadyExistsException |
A unique value already exists. |
BadRequestException |
Invalid input / bad request. |
InternalServerException |
Unexpected server-side failure. |
DeleteException |
A delete couldn't be completed. |
ValidationException |
Carries per-field validation errors (see below). |
FileServiceException, IdentityServiceException, LanguageNotDefinedException, RefreshTokenException |
Common service/infra failures. |
throw new NotFoundException("User", "Id", id);
throw new BadRequestException("The 'from' date must be before 'to'.");
Catch the base type to handle any of them:
catch (CustomException ex) { /* map to an HTTP response, log, etc. */ }
Validation errors
ValidationException turns FluentValidation failures into a per-field dictionary, and its
message is JSON:
var result = validator.Validate(request);
if (!result.IsValid)
throw new ValidationException(result.Errors);
// ex.Failures => { "Email": ["'Email' is not a valid email."], ... }
Localized messages
The resource-based exceptions (NotFoundException, AlreadyExistsException, DeleteException,
…) look up their message by key (NotFoundError, AlreadyExistsError, DeleteError, …) from a
ResourceManager found in your loaded assemblies. Add a .resx with those keys (and culture
variants) and the messages are formatted with the supplied arguments. If no matching resource is
found, the exception falls back to a !!Key!! placeholder so nothing crashes.
Contributing & releases
Versioning is automated from Conventional Commits — see CONTRIBUTING.md.
License
MIT — see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- FluentValidation (>= 12.1.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on GM.Exceptions:
| Package | Downloads |
|---|---|
|
GM.API.Application
Application-layer building blocks for the GM.API stack: GM.Mediator wiring plus validation and performance pipeline behaviours, and paged-list models. Part of the GM.API family. |
|
|
GM.API
An opinionated ASP.NET Core Web API starter for .NET. A single AddGMAPI/UseGMAPI pair wires up controllers, CORS, API versioning, Swagger docs, FluentValidation, Serilog, and middlewares for exception handling, request logging (with sensitive-data masking) and request localization. Bundles the GM.API.* companion packages. |
|
|
GM.API.Middlewares
ASP.NET Core middlewares for the GM.API stack: exception handling (ProblemDetails), request logging with sensitive-data masking, and request localization. Part of the GM.API family. |
GitHub repositories
This package is not used by any popular GitHub repositories.