Summary
The Invite Friends form sets sending before posting to /api/referrals, then assumes both the request and res.json() succeed. If the network request rejects or the server returns a non-JSON error body, the handler throws before resetting sending, leaving the button stuck in "Sending..." and no useful error message shown.
Steps to reproduce
- Open
/dashboard/referrals.
- Enter an email address.
- Make
POST /api/referrals fail at the network layer, or return an invalid/non-JSON error response.
- Click Send Invites.
Expected
The page should recover, re-enable the Send Invites button, and show a clear error.
Actual
The unhandled failure path can leave the form stuck in the loading state.
Proposed fix
Wrap the invite POST flow in try/catch/finally, tolerate non-JSON error responses, and always reset sending.
Summary
The Invite Friends form sets
sendingbefore posting to/api/referrals, then assumes both the request andres.json()succeed. If the network request rejects or the server returns a non-JSON error body, the handler throws before resettingsending, leaving the button stuck in "Sending..." and no useful error message shown.Steps to reproduce
/dashboard/referrals.POST /api/referralsfail at the network layer, or return an invalid/non-JSON error response.Expected
The page should recover, re-enable the Send Invites button, and show a clear error.
Actual
The unhandled failure path can leave the form stuck in the loading state.
Proposed fix
Wrap the invite POST flow in
try/catch/finally, tolerate non-JSON error responses, and always resetsending.