@@ -7,12 +7,24 @@ Rejected Promises should be caught so we can return a friendly error state.
77
88🐨 Open <InlineFile file = " index.ts" /> and:
99
10- 1 . Update ` getUserProfile ` to handle rejections with ` .catch() `
11- 2 . Return an error result when the Promise rejects
12- 3 . Keep the ` id ` parameter flowing through both functions
13- 4 . Export ` fetchUser ` and ` getUserProfile `
10+ 1 . Keep ` fetchUser(id) ` as provided:
11+ - ` id === '1' ` resolves to Alice (` id: '1' ` , ` name: 'Alice' ` ,
12+ ` email: 'alice@example.com' ` )
13+ - any other id rejects with ` Error('User not found') `
14+ 2 . Update ` getUserProfile(id) ` to handle rejections with ` .catch() `
15+ 3 . Return shapes:
16+ - success: ` { status: 'success', user } `
17+ - error: ` { status: 'error', message } ` where ` message ` is
18+ ` error.message ` when the rejection is an ` Error ` , otherwise
19+ ` 'Unknown error' `
20+ 4 . Export both ` fetchUser ` and ` getUserProfile `
1421
15- 💰 For the error result, return a ` { status: 'error', message: string } ` object.
16- If the value isn't an ` Error ` , use ` 'Unknown error' ` as the message.
22+ Completion checks:
23+
24+ - ` await getUserProfile('1') ` → ` { status: 'success', user: { id: '1', ... } } `
25+ - ` await getUserProfile('missing') ` →
26+ ` { status: 'error', message: 'User not found' } `
27+ - ` await fetchUser('missing') ` still rejects (do not swallow that rejection
28+ inside ` fetchUser ` itself)
1729
1830📜 [ MDN - Promise.prototype.catch()] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch )
0 commit comments