---
name: "express-async-errors-middleware"
description: "Eliminate unhandled promise rejections and try-catch boilerplate in Express applications."
metadata:
  author: "Express"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "handle async errors express"
  - "express centralized error middleware"
  - "express 5 error handling"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Express Async Errors & Centralized Error Middleware

Configures Express error handling: using express-async-errors or native Express 5 promise support, authoring centralized error middleware (err, req, res, next), formatting operational vs programmer errors, and status codes.

## When to Invoke
Invoke this skill whenever you need to:
- handle async errors express
- express centralized error middleware
- express 5 error handling

## Execution SOP & Rules
1. Import 'express-async-errors' at root of application or migrate to Express 5.
2. Throw custom operational errors: throw new AppError('Resource not found', 404) directly in async handlers.
3. Define error middleware at the very end of app: app.use((err, req, res, next) => { res.status(err.statusCode || 500).json(...) }).
4. Ensure error middleware takes exactly 4 parameters (err, req, res, next) so Express recognizes it.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
