Build Robust Error Handling Middleware
Generate production-ready error handling middleware for your backend API. Includes logging, status codes, and validation patterns.
Prompt Template
Variables to Customize
[FRAMEWORK] The backend framework being used
Example: Express.js
[ERROR_TYPES] Specific types of errors to handle
Example: validation errors, authentication errors, database errors, external API errors
[LOGGING_SERVICE] The logging service or library to use
Example: Winston
[ENVIRONMENT] The deployment environment
Example: production
[INCLUDE_STACK_TRACES] Whether to include stack traces in responses
Example: only in development
Example Output
Pro Tips for Best Results
- Always log errors with sufficient context (request details, user info, timestamp) for debugging
- Create specific error classes for different types of failures to handle them appropriately
- Never expose sensitive information like database credentials or internal paths in error messages
- Use different log levels (error, warn, info) to categorize the severity of issues
- Test your error handling with various edge cases and malformed requests
Tags
Want 500+ Expert Prompts?
Get the Premium Prompt Pack — organized, tested, and ready to use.
Get it for $29Related Prompts You Might Like
Generate a Comprehensive Code Review Checklist
Act as a senior software engineer and create a comprehensive code review checklist for [PROGRAMMING_LANGUAGE] projects. ...
Implement WebSocket Connections
I need you to implement a complete WebSocket connection system for [APPLICATION_TYPE]. Please provide both client-side a...
Write End-to-End Tests
You are an expert QA engineer specializing in end-to-end testing. I need you to write comprehensive E2E test cases for a...
Implement API Pagination System
I need to implement pagination for a REST API endpoint. Please provide a complete implementation with the following requ...
Convert JavaScript to TypeScript
You are an expert TypeScript developer tasked with converting JavaScript code to TypeScript. Please convert the followin...
Optimize JavaScript Bundle Size
You are an expert frontend performance engineer specializing in bundle optimization. I need you to analyze my JavaScript...