error-handling-backend

Implement global exception handling and structured logging for .NET APIs.

Updated Mar 28, 2026
One-click install
npx skills add https://github.com/congiuluc/my-awesome-copilot --skill error-handling-backend
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling-backend
Source: https://github.com/congiuluc/my-awesome-copilot/tree/main/skills/error-handling-backend
Command: npx skills add https://github.com/congiuluc/my-awesome-copilot --skill error-handling-backend

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Implement consistent backend error handling with global exception handlers, custom domain exceptions, and a standardized error envelope to improve reliability and security across APIs.

Core Features & Use Cases

  • Global exception handling middleware to catch and standardize errors
  • Custom domain exceptions such as NotFoundException, ValidationException, and ConflictException
  • Mapping of domain errors to appropriate HTTP status codes and ApiResponse error payloads
  • Structured logging with Serilog to preserve context and diagnostics
  • Optional resilience patterns with Polly for transient failures

Quick Start

Set up the global exception handler and define domain exceptions to enable structured ApiResponse errors.

Frequently Asked Questions about error-handling-backend

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

FAQPage Schema
How do I implement global exception handling in ASP.NET Core to standardize API error responses?

Standardize backend error handling by implementing IExceptionHandler middleware to catch exceptions globally and return consistent ApiResponse error envelopes with appropriate HTTP status codes.

What is the best way to map custom domain exceptions to HTTP status codes in a .NET API?

Mapping custom domain exceptions to HTTP status codes is achieved by defining NotFoundException, ValidationException, and ConflictException classes that translate domain errors into appropriate HTTP status codes within ApiResponse payloads.

How does Serilog integration work with structured logging for API error diagnostics?

Serilog integration captures structured logs during global exception handling to preserve diagnostic context and request details when domain exceptions or API errors occur.

Can I use Polly resilience patterns alongside global exception handlers for transient API failures?

Yes, optional Polly resilience patterns integrate with global exception handlers to retry transient failures while standardizing error envelopes and Serilog logging for remaining exceptions.

Do I need to implement IExceptionHandler to standardize error envelopes in ASP.NET Core APIs?

Yes, implementing IExceptionHandler is required to intercept global exceptions and format them into standardized ApiResponse-backed error envelopes with proper HTTP status mapping.

Why should I use a standardized error envelope instead of raw exception messages in API responses?

A standardized error envelope prevents sensitive exception details from leaking while providing consistent ApiResponse structures for clients to parse and handle domain errors uniformly.