Library › Coding AI › College students

Convert a promise chain to async/await with three new rules

Practice: Giving the right context. About 5 minutes.

About this exercise

For your intramural league site, convert loadRoster to async/await with try/catch and no .then or .catch. Three changes your team agreed on: pass a 5-second timeout to fetch with signal: AbortSignal.timeout(5000); a 404 means the team was deleted, so return [] without logging; and other errors now use console.warn instead of console.error. Keep the export, name, parameter, filter and sort. Exactly 1 code block of at most 18 lines, under 20 words of text.

Common mistakes when you ask AI for this

  • Missing the timeout. The AI converts the syntax but can't know the API hangs; you have to ask for the timeout. Try: Add: "Pass { signal: AbortSignal.timeout(5000) } to fetch."
  • Treating 404 like any error. The AI keeps one error path, so deleted teams still hit the logs. Try: Add: "If res.status is 404, return [] without logging."
  • Keeping console.error. A straight conversion keeps console.error, which pages your team. Try: Add: "Use console.warn in the catch."
  • A long explanation. The AI explains async/await and shows before and after. Try: Add: "One code block with just the function, no text."

What a strong prompt includes

  • Asks for the timeout
  • Handles 404
  • Switches to warn
  • Keeps the behavior
  • Asks for only the function

Practice this now ↑

Related exercises