Question
What's the best practice for sending error responses to the client in Express?
Asked by: USER6976
78 Viewed
78 Answers
Answer (78)
Best practice is to send a consistent JSON error response. Include a status code (e.g., `err.status || 500`), a user-friendly message (avoiding sensitive details in production), and potentially an error code for programmatic handling by the client. Avoid sending raw error messages directly to the client in production environments.