06 / 17

How do you handle the result of a Promise?

You can use the .then() method on a Promise to handle its successful resolution and use the .catch() method to handle errors.

javascript
Difficulty: 4/10
Topics: promise chaining, async/await, error handling

Scenario Questions

0-2 years experience
  1. 1

    You need to fetch user data with fetch() and then display the name. How would you handle the promise result to update the UI?

  2. 2

    If the API call fails, what code would you write to show an error message to the user?

2-5 years experience
  1. 1

    We have a function that calls two APIs sequentially, each returning a promise. How would you structure the code so the second call only runs after the first resolves, and handle any errors that might occur in either step?

  2. 2

    During a code review you notice a promise chain where a .then handler does not return anything, causing the next .then to receive undefined. How would you fix it and why does it matter?

5-8 years experience
  1. 1

    Our service aggregates data from five micro‑services using Promise.all. Occasionally one service times out, causing the whole request to fail. How would you redesign the handling to still return partial results while logging the failure?

  2. 2

    We have a legacy codebase that mixes callbacks and promises, and we’re seeing unhandled promise rejections in production. What strategy would you use to systematically migrate and ensure proper error handling across the module?

8+ years experience
  1. 1

    At the organization level we want to enforce a policy that all async work must surface errors to a central monitoring system. How would you design a framework or pattern for handling promise results globally without littering try/catch throughout the codebase?

  2. 2

    We are planning to move a large monolith to a serverless architecture where each function returns a promise to the orchestrator. What considerations around promise handling, timeouts, and error propagation should guide the design of the orchestration layer?

Follow-up Questions

  • What difference does returning a value vs. returning a promise inside a then callback make?
  • How would you surface an error from deep inside a promise chain to the top level?
  • When would you prefer async/await over explicit then/catch chaining?