error handling on wrong input in search bar
All checks were successful
Docker Build & Publish / Build Docker (push) Successful in 1m9s

This commit is contained in:
ChrQR 2024-05-12 21:58:10 +02:00
parent fcbb0b369a
commit 584176baff
2 changed files with 4 additions and 1 deletions

View File

@ -10,6 +10,9 @@ export async function getLocation(searchLocation: string): Promise<coordType>{
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

View File

@ -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<HTMLInputElement>) => {