error-handling

Implement the Result Pattern with Failure objects and middleware for unified HTTP error mapping.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/yaochangyu/ai-dev-toolkit --skill error-handling-yaochangyu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/yaochangyu/ai-dev-toolkit/tree/main/.github/skills/error-handling
Command: npx skills add https://github.com/yaochangyu/ai-dev-toolkit --skill error-handling-yaochangyu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

This Skill standardizes and unifies error handling across application boundaries by employing the Result Pattern, enabling consistent failure representation, wrapping error information, and separating error concerns from business logic.

Core Features & Use Cases

  • Result-based flows: Apply a typed Result/Failure model to service and repository boundaries to represent success and failure explicitly.
  • Failure object design: Implement a structured Failure class with Code, Message, TraceId, and extensibility data to carry rich error context.
  • HTTP mapping & layering: Map FailureCode values to HTTP status responses in a clean, layered architecture (Repository, Handler, Controller, Middleware) for predictable client-facing errors.
  • Reference patterns: Follow best practices and templates (e.g., Failure templates and pattern guidelines) to ensure consistent error handling across services.

Quick Start

Introduce a common Failure type and FailureCode, wire a global exception middleware, and refactor core paths to return Result/Failure through repository and service layers.

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 across application layers in ASP.NET Core?

Standardize error handling in ASP.NET Core by implementing the Result Pattern with a Failure object and middleware. This separates error concerns from business logic, ensuring consistent failure representation across repositories, handlers, and controllers.

What is the Result Pattern for representing failures in C#?

The Result Pattern represents failures explicitly using a typed Result object wrapping a structured Failure class. This class carries rich error context including Code, Message, TraceId, and extensibility data instead of relying on exceptions.

How do I map error codes to HTTP status codes in a layered architecture?

Map error codes to HTTP status responses by using a FailureCode enumeration within your middleware. This ensures predictable client-facing errors by cleanly translating internal application layer failures into correct HTTP responses.

Does ASP.NET Core middleware support centralized exception handling with the Result Pattern?

ASP.NET Core middleware supports centralized exception handling by wiring a global flow that catches exceptions. Refactoring core paths to return typed Result objects through repository and service layers unifies all responses globally.

What is the best way to unify API error responses without throwing exceptions?

Unify API error responses by adopting the Result Pattern to return a common Failure type instead of throwing exceptions. This approach standardizes failure representation and separates error concerns from core business logic.

When should I use a FailureCode enumeration instead of raw exception messages?

Use a FailureCode enumeration when you need predictable HTTP status mapping and consistent error context across application boundaries. It replaces raw exception messages with structured codes, messages, and TraceIds for reliable client responses.