error-handling

Define domain-specific exceptions and a global handler for HTTP error mapping.

10|1|Updated Mar 8, 2026
One-click install
npx skills add https://github.com/andresdiegolanda/design-first-ai --skill error-handling-andresdiegolanda
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/andresdiegolanda/design-first-ai/tree/main/context/skills/error-handling
Command: npx skills add https://github.com/andresdiegolanda/design-first-ai --skill error-handling-andresdiegolanda

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Backend services often mix generic exceptions with business-condition failures, causing inconsistent HTTP responses. This Skill centralizes error semantics by introducing domain-specific exceptions and a GlobalExceptionHandler to translate failures into clear, consistent API errors.

Core Features & Use Cases

  • Named exceptions per failure category: separate exception classes for Not found, Validation failure, External service failure, and Configuration error.
  • Global exception handling: a central advice/controller that maps domain failures to appropriate HTTP status codes and error payloads.
  • Guardrails for service code: throw at the point of failure with descriptive business messages; log at the boundary only.

Quick Start

Define domain-specific exceptions and a global handler, then apply them at the point of failure in a service method.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I implement consistent error handling for backend services in Java?

To implement consistent error handling, define named exceptions for failure categories like not found or validation failure, then map them to HTTP status codes in a global exception handler. This centralizes error semantics and ensures uniform API responses across backend services.

Why does my Spring backend return inconsistent HTTP status codes for domain failures?

Inconsistent HTTP responses occur when generic exceptions are mixed with business failures. Using domain-specific exceptions for each failure category and a global exception handler standardizes the translation of domain failures into consistent HTTP status codes and error payloads.

What is the best way to map domain exceptions to HTTP responses in Spring?

The best way to map domain exceptions to HTTP responses is using a global exception handler. This central controller advice intercepts domain-specific exceptions thrown at the point of failure and translates them into appropriate HTTP status codes and structured error payloads.

Can I use a global exception handler for validation and external service failures in Java?

Yes, a global exception handler can manage validation and external service failures. By creating named exception classes for each failure category, the handler centralizes HTTP mapping and translates these distinct domain failures into clear API errors with appropriate status codes.

When should I throw domain-specific exceptions in backend service code?

Domain-specific exceptions should be thrown at the exact point of failure in service code with descriptive business messages. Logging should occur at the boundary only, ensuring exceptions accurately model domain failures before the global handler translates them to HTTP responses.