Error handling

From andresdiegolanda/design-first-ai · View interactive version

Error handling is an AI agent skill from the GitHub repository andresdiegolanda/design-first-ai. Named exceptions and global handler for the Spring MVC demo. Use when adding any method that can fail with a domain reason.

How to use this skill

Skill file

Skill: Error Handling (spring-mvc-demo)

Pattern — one named exception per failure category

public class ProductNotFoundException extends RuntimeException {
    public ProductNotFoundException(UUID id) {
        super("Product not found: " + id);
    }
}

Rules

Adding a new exception

  1. Create {Concept}Exception extends RuntimeException in exception/.
  2. Add @ExceptionHandler in GlobalExceptionHandler with the correct HTTP status.
  3. Return new ErrorResponse("SNAKE_CASE_CODE", ex.getMessage()).

Design Constraints

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.