Skip to content

Handle geolocation error messages - #761

Open
RaulBSanchez wants to merge 1 commit into
developfrom
rbazan/760
Open

Handle geolocation error messages#761
RaulBSanchez wants to merge 1 commit into
developfrom
rbazan/760

Conversation

@RaulBSanchez

Copy link
Copy Markdown
Contributor

Pull Request

Change Summary

Updated getUserLocation to return the browser geolocation error message instead of null when location access fails.

Before:

type GetUserLocationReturn = [UserLocation, false] | [null, true];

After:

type GetUserLocationReturn = [UserLocation, false] | [string, true];

This allows the error message returned from the browser to be passed through the application.

Updated UseMyLocationButton.tsx to use the returned value from getUserLocation.

Before, all location errors displayed a hardcoded message:

const onUseMyLocationClick = async () => {
  const [userLocation, isLocationServicesDisabled] = await getUserLocation();

  if (isLocationServicesDisabled) {
    return onError('Location services must be enabled for this feature');
  }

  onSuccess(userLocation);
};

After, the browser error message is passed to onError:

const onUseMyLocationClick = async () => {
  const [value, isLocationServicesDisabled] = await getUserLocation();

  if (isLocationServicesDisabled) {
    return onError(value);
  }

  onSuccess(value);
};
  • Updated EstimatedWalkTime.tsx to store and display location error messages.

Added state:

const [locationErrorMessage, setLocationErrorMessage] = useState('');

Changed:

onError={() => refetch()}
onSuccess={() => refetch()}

to:

onError={message => {
  setLocationErrorMessage(message);
  refetch();
}}
onSuccess={() => {
  setLocationErrorMessage('');
  refetch();
}}

Change Reason

Previously, when geolocation failed, the application only tracked that an error occurred and displayed a generic message. The actual browser geolocation error message was not being used.

These changes allow the browser-provided error message to flow from getUserLocation, through UseMyLocationButton, and into EstimatedWalkTime.tsx, where it can be displayed to the user.

This provides clearer feedback when location permissions fail or location services are unavailable.

Verification [Optional]

Screenshot 2026-07-07 at 10 40 36 AM

Related Issue: #<732>

@RaulBSanchez
RaulBSanchez requested a review from gcardonag July 7, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant