exception-handling

Implements layered exception handling with domain exception hierarchies and RFC 7807 ProblemDetail responses.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/balajirags/aifsd-kit --skill exception-handling-balajirags
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: exception-handling
Source: https://github.com/balajirags/aifsd-kit/tree/main/docs/skills/exception-handling
Command: npx skills add https://github.com/balajirags/aifsd-kit --skill exception-handling-balajirags

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? APIs often return inconsistent error shapes, leak stack traces to clients, or swallow failures silently. This Skill enforces a single layered exception strategy so every error response is consistent, safe, and traceable. ## Core Features & Use Cases - Domain Exception Hierarchy: Defines a small exception tree under one base class carrying a stable, machine-readable errorCode instead of bare RuntimeExceptions. - Global Error Mapping: Routes all exceptions through a @ControllerAdvice handler that maps domain exceptions to RFC 7807 ProblemDetail responses. - Boundary Translation: Converts integration exceptions (Feign, JPA, Kafka) into domain exceptions at the boundary so raw client errors never reach controllers. - Use Case: When building a Spring Boot REST API, apply these rules so a missing resource returns a consistent 404 ProblemDetail with an errorCode, while unexpected failures are logged at ERROR and return a safe generic 500. ## Quick Start Apply the exception-handling skill to refactor this Spring Boot service so all errors go through a global ControllerAdvice returning RFC 7807 ProblemDetail responses.

Frequently Asked Questions about exception-handling

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

FAQPage Schema
How do I implement global exception handling in Spring Boot?

Use a @ControllerAdvice class with @ExceptionHandler methods that map each domain exception to an HTTP status and return an RFC 7807 ProblemDetail body. Controllers never catch business exceptions themselves; the global handler produces every error response.

What is RFC 7807 ProblemDetail and how do I return it?

RFC 7807 ProblemDetail is a standardized HTTP error response format with fields like status, detail, and type. In Spring, use ProblemDetail.forStatusAndDetail(status, message) and attach custom properties such as a machine-readable errorCode.

Should controllers catch exceptions in a REST API?

No. Controllers should let exceptions propagate to a global @ControllerAdvice handler. Per-endpoint try/catch blocks produce inconsistent error shapes across the API and duplicate mapping logic.

How do I handle Feign or JPA exceptions in a layered architecture?

Translate integration exceptions like FeignException or DataAccessException into domain exceptions at the integration boundary. This prevents raw client or database errors from leaking up to the controller layer.

Why should APIs not return stack traces in error responses?

Stack traces expose internal class names, SQL fragments, and file paths to clients, creating a security risk. Log the full exception server-side at ERROR level and return only safe ProblemDetail fields to the client.

When should I avoid using exceptions for control flow?

Avoid exceptions for expected outcomes, such as a routine lookup-or-create path where absence is normal. Reserve exceptions for genuinely exceptional conditions and use Optional or explicit branching for routine cases.