TGViewer
Coding Interview Preparation Coding Interview Preparation @coding_interview_preparation · 5.9K subscribers
Post #1198 469
✅ Backend Basics Interview Questions – Part 5 (Error Handling) 🚀💻 

📍 1. What is Error Handling? 
A:
Error handling is the process of catching and responding to errors that occur during request processing, ensuring the server doesn’t crash and clients get meaningful messages. 

📍 2. Built-in Error Handling
- Express automatically catches errors in synchronous routes. 
- Example: 
app.get('/error', (req, res) => {
  throw new Error('Something went wrong!');
});

📍 3. Custom Error-handling Middleware 
- Middleware with 4 parameters (err, req, res, next) handles errors globally. 
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send({ message: err.message });
});

📍 4. Try-Catch in Async Functions
- Async route handlers need try-catch to handle errors. 
app.get('/async', async (req, res, next) => {
  try {
    const data = await getData();
    res.send(data);
  } catch (err) {
    next(err);
  }
});

📍 5. Sending Proper Status Codes 
- 400 → Bad Request 
- 401 → Unauthorized 
- 403 → Forbidden 
- 404 → Not Found 
- 500 → Internal Server Error 

📍 6. Error Logging
- Use console.error() or logging libraries like winston or morgan for debugging.

📍 7. Best Practices
- Keep error messages user-friendly. 
- Don’t expose stack traces in production. 
- Centralize error handling. 
- Validate inputs to prevent errors early. 

💬 Tap ❤️ for more!
  • ❤ 3
More from @coding_interview_preparation
  1. Oct 10, 2026100 SQL interview questions
  2. Oct 8, 2026If you're prepping for system design interviews, this repo is gold It contains a curated,…
  3. Oct 6, 2026document post
  4. Oct 4, 2026💼 Why Your Resume Gets Rejected Before a Human Reads It You may have good skills and proj…
  5. Oct 2, 2026🧠 Coding Myths You Should Stop Believing There's a lot of advice online about learning to…
  6. Oct 1, 2026Most Asked Topics in AI Engineer Interviews Based on 2026 candidate reports
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →