diff --git a/app/actions.ts b/app/actions.ts index 3d73839..b2903ae 100644 --- a/app/actions.ts +++ b/app/actions.ts @@ -10,6 +10,9 @@ export async function getLocation(searchLocation: string): Promise{ throw new Error(`There was an error fetching the data`); } const data: LocationType = await res.json(); + if (!data.results[0].formatted_address){ + throw new Error(`Unable to find the address`); + } return { name: data.results[0].formatted_address, geo: data.results[0].geometry.location diff --git a/components/LocationSearch.tsx b/components/LocationSearch.tsx index 8f3bc96..048aa31 100644 --- a/components/LocationSearch.tsx +++ b/components/LocationSearch.tsx @@ -5,7 +5,7 @@ import { LocationContext } from "@/context/LocationContext"; export default function LocationSearch() { const [searchLocation, setSearchLocation] = useState(""); - const { geoLocation, setGeoLocation } = useContext(LocationContext); + const { setGeoLocation } = useContext(LocationContext); const [pending, setPending] = useState(false); const handleChange = (e: React.ChangeEvent) => {