javascript-code-style

Automate try-catch error handling in JavaScript Express API routes.

Updated Oct 5, 2025
One-click install
npx skills add https://github.com/iamyojimbo/prompts --skill javascript-code-style
Or copy as Structured Prompt for Agentβ–Ό
Please help me install this Agent Skill.
Skill: javascript-code-style
Source: https://github.com/iamyojimbo/prompts/tree/main/skills/javascript-code-style
Command: npx skills add https://github.com/iamyojimbo/prompts --skill javascript-code-style

SYSTEM DOCUMENTATION & REQUIREMENTS

πŸ’‘ This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

JavaScript developers often struggle with inconsistent error handling across Express API routes, leading to hard-to-debug failures and missed user feedback in the ECP codebase.

Core Features & Use Cases

  • Guaranteed error boundaries: Always wrap async route handlers in try-catch to prevent unhandled rejections and improve reliability.
  • Standardized error responses: Use setErrorResponse(res, title, detail, status) for consistent client feedback.
  • Observability and safety: Log errors with console.error() before returning responses, and apply appropriate status codes (400 for client errors, 500 for server errors).

Quick Start

Apply these guidelines to an Express API route in the api/ directory and wrap all async handlers with proper error handling.

Frequently Asked Questions about javascript-code-style

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

FAQPage Schema
How do I enforce consistent error handling in Express API routes?β–Ό

Consistent error handling in Express API routes is enforced by wrapping async route handlers in try-catch blocks to prevent unhandled rejections and ensure reliable API responses.

What is the best way to standardize error responses in JavaScript Express applications?β–Ό

To standardize error responses in JavaScript Express applications, use a dedicated function like setErrorResponse(res, title, detail, status) to return consistent client feedback across all route handlers.

How do I prevent unhandled promise rejections in Express route handlers?β–Ό

Unhandled promise rejections in Express route handlers are prevented by applying try-catch wrapping to all async handlers within the api/ directory, catching errors before they crash the service.

When should I use 400 vs 500 status codes for API errors in Express?β–Ό

Use 400 status codes for client errors and 500 status codes for server errors when handling API responses in Express, ensuring the correct error type is communicated to the client.

Does this JavaScript coding standard apply to middleware or only route files?β–Ό

These JavaScript coding standards apply to API route files under the api/ directory across Express-based services, covering route handlers, middlewares, and error response patterns.

Why should I log errors with console.error before returning an API response?β–Ό

Logging errors with console.error before returning an API response provides observability and safety, capturing the failure details in the service logs before sending the standardized error response to the client.