Return an empty array when country/state fetch fails
What does this MR do?
The Apollo local resolvers for countries and states caught a failed fetch
and returned the value of createAlert() — an alert object, not an array. The
query therefore resolved successfully with a non-array value, and every
caller doing data.countries.map(...) threw:
TypeError: e.countries.map is not a function
TypeError: e.states.map is not a functionThis returns [] from the failure path instead. The user still sees the alert;
the dropdown renders empty rather than the component throwing.
- .catch(() => createAlert({ message: ERROR_FETCHING_COUNTRIES }));
+ .catch(() => {
+ createAlert({ message: ERROR_FETCHING_COUNTRIES });
+ return [];
+ });Why fix the resolver rather than the callers
country_state_mixin backs six components, so a resolver-level fix covers all
of them and keeps the query's contract ("this returns an array") intact:
registrations/components/free_welcome_form.vueregistrations/components/trial_welcome_form.vueregistrations/components/company_form.vuetrials/components/create_trial_form.vuepages/gitlab_subscriptions/self_managed/trials/components/create_trial_form.vuehand_raise_leads/hand_raise_lead/components/hand_raise_lead_modal.vue
A defensive data.countries ?? [] in the mixin would also stop the throw, but
it would mask the failure at each call site instead of fixing the source.
Test gap this closes
The existing error specs asserted only that the alert fired, never what the resolver returned — which is how this shipped. Both error cases now assert the return value. Verified they fail without the fix and pass with it.
Out of scope
Whether an empty dropdown is the right UX, or the form should offer a retry, is a separate question raised in the issue.
References
- #618751 (closed)
- Sentry (~30 users, 7d): https://new-sentry.gitlab.net/organizations/gitlab/issues/3344056/
How to set up and validate locally
- Block or fail the
/-/countriesrequest (devtools request blocking, or a 500). - Visit
/users/sign_up/welcome. - Before: the country dropdown does not render and the console shows
TypeError: e.countries.map is not a function. After: an alert appears and the dropdown renders empty.