error-handling

Standardize .NET API error handling with typed results and ProblemDetails.

4|Updated Apr 20, 2026
One-click install
npx skills add https://github.com/zdanovichnick/dotnet-pilot --skill error-handling-zdanovichnick
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/zdanovichnick/dotnet-pilot/tree/main/skills/error-handling
Command: npx skills add https://github.com/zdanovichnick/dotnet-pilot --skill error-handling-zdanovichnick

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Error handling in .NET often becomes inconsistent, leaking internal exceptions to clients and making it hard to model expected failures like not found, validation errors, and business rule conflicts.

Core Features & Use Cases

  • Typed result-based flows: Use Result<TValue, TError> to represent expected domain outcomes without throwing for normal control flow.
  • RFC 7807 ProblemDetails responses: Return standardized ProblemDetails payloads for 4xx/5xx responses from ASP.NET Core.
  • Global exception boundaries: Centralize unhandled exception handling at the HTTP boundary (and job boundaries) while keeping service/repository layers clean.
  • Typed error records: Define discriminated domain error records (e.g., NotFound, Conflict, Forbidden, Validation) to enable precise HTTP mapping.

Quick Start

Ask an AI to refactor your service and API layer to return Result<T, DomainError> for domain failures and map those errors to ProblemDetails using a global exception handler.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I standardize error handling in ASP.NET Core APIs using ProblemDetails?

Standardize ASP.NET Core API error handling by mapping domain failures to RFC 7807 ProblemDetails responses and centralizing unhandled exceptions in a global exception handler. This ensures clients receive consistent, safe 4xx and 5xx payloads.

What is the Result pattern for .NET domain errors?

The Result pattern uses a typed `Result<TValue, TError>` structure to represent expected domain outcomes without throwing exceptions. It enables explicit, type-safe error handling flows for normal application logic.

How do I map typed domain errors to HTTP responses in .NET Minimal APIs?

Map typed domain errors to HTTP responses by defining discriminated error records like NotFound or Conflict, then translating them into typed HTTP responses within an HTTP boundary exception handler that emits ProblemDetails.

When should I use a global exception handler in ASP.NET Core?

Use a global exception handler in ASP.NET Core to centralize unhandled exceptions at the HTTP boundary. This keeps service and repository layers clean while ensuring unexpected infrastructure failures emit safe ProblemDetails responses.

Does this error handling approach work with both Minimal APIs and controller endpoints?

Yes, this approach applies to both ASP.NET Core Minimal APIs and controller endpoints. It standardizes failure translation using typed result patterns and ProblemDetails across different endpoint architectures.

Why should I avoid throwing exceptions for normal domain rule violations in .NET?

Throwing exceptions for normal domain rule violations leaks internal failures and complicates control flow. Using typed result patterns instead allows you to model expected outcomes like validation issues safely without throwing.