Code Room
Code reviewMediumcr-g353
Subject Inconsistent errorsLevel Mid–Senior~20 minCommon in Databases & SQL interviewsIndustries Software development

Question

Review these two TypeScript handlers from the same service. A client wants one error-handling code path for both.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewtypescript
// POST /loginapp.post('/login', (req, res) => {  if (!valid(req.body)) {    return res.status(400).json({ error: 'invalid credentials' });  }  // ...}); // POST /ordersapp.post('/orders', (req, res) => {  if (!req.body.items?.length) {    return res.status(422).send('items required');  }  if (!authorized(req)) {    return res.json({ ok: false, message: 'forbidden', code: 1037 });  }  // ...});
Run or narrate your approach, then ask the coach.