secure-error-handling

Implement environment-aware error handlers that return generic client responses and log full details server-side.

15|1|Updated Oct 20, 2025
One-click install
npx skills add https://github.com/harperaa/secure-claude-skills --skill secure-error-handling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: secure-error-handling
Source: https://github.com/harperaa/secure-claude-skills/tree/main/error-handling
Command: npx skills add https://github.com/harperaa/secure-claude-skills --skill secure-error-handling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents attackers from exploiting detailed error messages to learn about your system architecture, database structure, and technology stack - eliminating a major security vulnerability.

Core Features & Use Cases

  • Environment-Aware Error Handling: Automatically provides full debugging details in development but only safe, generic messages in production.
  • Five Specialized Error Handlers: Handle API errors, validation failures, authentication issues, authorization problems, and missing resources with appropriate HTTP status codes.
  • Use Case: Imagine you're building a payment processing API. Use this Skill to automatically prevent exposing Stripe API details, database schemas, or file paths when errors occur.

Quick Start

Use the secure-error-handling skill to implement proper error handling for an API endpoint that processes user payments, ensuring no sensitive system information is leaked to clients.

Frequently Asked Questions about secure-error-handling

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

FAQPage Schema
How do I prevent sensitive information from leaking in API error messages?

Secure error handling prevents information leakage by returning generic messages to clients in production while logging full details server-side. Implement environment-aware handlers that expose stack traces and system details only in development, blocking attackers from learning your architecture, database structure, or technology stack.

What's the best way to handle validation errors without exposing database schema details?

Use specialized validation error handlers that sanitize responses based on environment. In production, return safe, user-friendly validation messages; in development, include schema context and debugging details. This approach prevents database structure exposure while maintaining developer productivity.

How do I implement different error handlers for authentication and authorization failures?

Separate handlers for authentication (401) and authorization (403) errors allow granular control over what information clients receive. Implement handleUnauthorizedError and handleForbiddenError to return appropriate HTTP status codes and generic messages in production while preserving full context for server-side investigation.

Can I use secure error handling for REST APIs that return different status codes?

Yes. Secure error handling supports multiple HTTP status codes through specialized handlers: handleApiError for general failures, handleValidationError for input issues, handleUnauthorizedError for 401, handleForbiddenError for 403, and handleNotFoundError for 404. Each returns environment-appropriate responses.

Why should I log full error details server-side if I'm hiding them from clients?

Server-side logging captures complete stack traces, environment variables, and request context for debugging without exposing this sensitive data to potential attackers. This approach balances security with operational visibility, enabling your team to investigate production issues while preventing information disclosure.