GM.Exceptions 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GM.Exceptions --version 1.2.0
                    
NuGet\Install-Package GM.Exceptions -Version 1.2.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="GM.Exceptions" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GM.Exceptions" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="GM.Exceptions" />
                    
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 GM.Exceptions --version 1.2.0
                    
#r "nuget: GM.Exceptions, 1.2.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 GM.Exceptions@1.2.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=GM.Exceptions&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=GM.Exceptions&version=1.2.0
                    
Install as a Cake Tool

GM.Exceptions

CI NuGet License: MIT

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 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.

GM.Documents

Document processing abstractions for the GM.* ecosystem. Provider-agnostic contracts — IDocumentConverter (transform an existing document: resize/compress/convert) and IDocumentGenerator<T> (produce a document from a plain data model) — over stream-based DocumentSource / DocumentResult / DocumentMetadata (page count, size, MIME type) that never leak the underlying libraries (OpenXML, ClosedXML, QuestPDF, ImageSharp) to consumers. Designed to sit between raw upload and persistence (validate/normalize/convert, then hand the output stream to GM.FileStorage) without coupling to it. Wire up with AddGMDocuments(); each document type ships in its own package (GM.Documents.Word / .Excel / .Pdf / .Images) so you only pull in what you need.

GM.RateLimiting

Distributed rate limiting for the GM.* ecosystem. A provider-agnostic IRateLimiterService with policy-based checks (TryAcquireAsync(key, policy)) and three per-policy algorithms — fixed window, sliding window, and token bucket. Counters live in GM.Caching so limits hold across every service instance (unlike ASP.NET Core's per-process limiter), and the check-and-increment is made atomic by a swappable store (default backed by GM.DistributedLock). Composable key strategies (per-user / per-API-key / per-IP / per-endpoint), policies from appsettings or fluent code, and a 429-friendly result (limit / remaining / retry-after). One call — AddGMRateLimiting() — to wire it up.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 180 7/30/2026
1.2.0 189 7/29/2026
1.1.0 149 7/2/2026
1.0.4 325 7/9/2025
1.0.3 225 7/9/2025
1.0.2 380 6/12/2025
1.0.1 363 6/12/2025
1.0.0 237 5/18/2025