error-handling

Implements Result pattern, ProblemDetails, and global exception middleware for ASP.NET Core ERP applications.

Updated Aug 18, 2026
One-click install
npx skills add https://github.com/Aurelian1974/ERPEnterprise --skill error-handling-aurelian1974
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/Aurelian1974/ERPEnterprise/tree/main/.github/skills/error-handling
Command: npx skills add https://github.com/Aurelian1974/ERPEnterprise --skill error-handling-aurelian1974

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Inconsistent error responses across an ERP backend make APIs hard to consume and debug. This Skill standardizes how business errors, validation failures, and technical exceptions are produced in .NET handlers and returned to clients as RFC 7807 ProblemDetails responses. ## Core Features & Use Cases - Result Pattern: Implements Result<T> and Error primitives so business failures are returned as values instead of thrown exceptions. - Global Exception Middleware: Catches ValidationException, DomainException, and unhandled exceptions, mapping each to the correct HTTP status with ProblemDetails payloads. - Controller Extensions: Provides ToActionResult extensions that map error codes like .not_found, .conflict, and .validation to 404, 409, and 422 responses. - Frontend Integration: Includes an Axios interceptor that handles 401 redirects, 403 toasts, and 422 validation errors for React Hook Form. - Use Case: When building a MediatR-based ASP.NET Core API, apply this pattern so a failed ApproveInvoiceCommand returns a structured 409 Conflict ProblemDetails response instead of an unhandled 500 error. ## Quick Start Ask the AI to implement the Result pattern with global exception middleware and ProblemDetails responses for your ASP.NET Core controller.

Frequently Asked Questions about error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement the Result pattern in C# for error handling?▼

Create Result and Result<TValue> classes with IsSuccess, Error, and static Success/Failure factory methods. Handlers return Result<T>.Failure(error) for business errors instead of throwing exceptions, and controllers convert the result via a ToActionResult extension.

How to return ProblemDetails from ASP.NET Core middleware?▼

Write an IMiddleware that wraps the request in try-catch, sets ContentType to application/problem+json, and serializes a ProblemDetails object with the appropriate status code. Map ValidationException to 422, DomainException to 400, and unhandled exceptions to 500.

Should business errors be thrown as exceptions or returned as Result?▼

Business errors should be returned as Result<T>.Failure(error), never thrown from handlers. Exceptions are reserved for technical failures like database outages, while domain rule violations inside entities can throw a DomainException caught by middleware.

How does FluentValidation integrate with MediatR pipeline behavior?▼

A ValidationBehavior<TRequest, TResponse> runs all registered IValidator<TRequest> instances before the handler. If any failures exist, it throws a ValidationException, which the global middleware converts into a 422 ValidationProblemDetails response with errors grouped by property.

Should stack traces be exposed in production API error responses?▼

No, stack traces must never be exposed in production. The middleware checks IWebHostEnvironment.IsDevelopment() and only includes exception details in the ProblemDetails Detail field during development, returning a generic message otherwise.