export function CatchBoundary() {
const caught = useCatch();
if (caught.status === 401) {
return <div>Error 401 occurred.</div>;
}
return <div>Please log in to access this page.</div>;
}
hard
A. Shows 'Please log in to access this page.' only for 403 errors, else generic error
B. Shows 'Please log in to access this page.' only for 401 errors, else generic error
C. Shows 'Access denied.' for 401 errors, else generic error
D. Shows 'Error 401 occurred.' for 401 errors, else 'Please log in to access this page.'
Solution
Step 1: Identify the correct status code and message
401 means Unauthorized, so the message should prompt login only for status 401.
Step 2: Check the conditional logic and fallback
Shows 'Please log in to access this page.' only for 401 errors, else generic error correctly checks for 401 and shows the login message only then, otherwise shows a generic error with status.
Final Answer:
Shows 'Please log in to access this page.' only for 401 errors, else generic error -> Option B
Quick Check:
401 status triggers login prompt in CatchBoundary [OK]
Hint: Match status code 401 exactly for login message [OK]
Common Mistakes:
Using wrong status code like 403
Showing login message for all errors
Mixing messages between conditions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.