error-handling

Implement backend error handling with custom classes and middleware.

7|4|Updated Feb 26, 2026
One-click install
npx skills add https://github.com/MadAppGang/magus --skill error-handling-madappgang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/MadAppGang/magus/tree/main/plugins/dev/skills/backend/error-handling
Command: npx skills add https://github.com/MadAppGang/magus --skill error-handling-madappgang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive strategies and code patterns for handling errors gracefully in backend applications, ensuring robustness and improving debuggability.

Core Features & Use Cases

  • Custom Error Classes: Define specific error types for better error categorization and handling.
  • Standardized Error Responses: Format error outputs consistently for APIs.
  • Middleware for Error Handling: Implement express middleware to catch and process errors.
  • Validation Error Handling: Integrate with libraries like Zod for input validation.
  • Retry Logic: Implement strategies for retrying failed operations.
  • Graceful Shutdown: Ensure applications shut down cleanly, releasing resources.
  • Use Case: When a user attempts to access a resource that does not exist, this skill ensures a 404 Not Found response is returned with a clear, standardized error message, preventing application crashes and providing helpful feedback.

Quick Start

Implement the provided express middleware to catch and format all errors in your application.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I implement centralized error handling middleware in Express?

Centralized Express error handling middleware catches and processes all application errors uniformly. You implement this middleware to format standardized API error responses, preventing application crashes and ensuring consistent client feedback across validation failures and unauthorized access.

How do I handle external service errors and implement retry logic in a backend application?

Backend retry logic handles external service errors by automatically re-executing failed operations. This Skill provides strategies to implement these retry patterns, ensuring your application maintains robustness when interacting with unreliable external dependencies or network requests.

What is the best way to standardize API error responses for validation failures and resource not found errors?

Standardized API error responses format validation failures and resource not found errors consistently. By defining custom error classes and using middleware, you return clear, uniform error messages with appropriate HTTP status codes, improving debuggability and providing helpful client feedback.

How does graceful shutdown work in backend services and when do I need it?

Graceful shutdown ensures backend services shut down cleanly by releasing resources and terminating active connections properly. You need this during production deployments or failures to prevent data loss and ensure system robustness when applications stop receiving traffic.

Can I integrate Zod input validation with custom error classes for API request handling?

Yes, you can integrate Zod input validation with custom error classes for API request handling. This combination allows you to categorize validation failures accurately and route them through standardized error handling middleware for consistent API responses.

Why does my Node.js backend crash on unhandled promise rejections instead of returning a 404 response?

Unhandled promise rejections crash Node.js backends when errors bypass centralized middleware. Implementing custom error classes and Express error handling middleware catches these failures, ensuring a standardized error response is returned instead of terminating the application process.