From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Handle geocode error - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Handle geocode error
All right, guys, so we have the maps displaying. However, the map is going to display if the address is correct, and it's there. So let's handle the case where it can't translate an address to latitude and longitude through geocoding. So if we go to one of our listings and just temporarily just put in some gibberish for the location and then update that, now you'll see it's just going to give us this constant loading spinner. So we want to handle that case. So in our property map, let's add a new piece of state. So we'll say const. And let's call this, we'll just call it geocode error. And then set geocode error. And set that to use state. And that's going to be false by default. And then down here in our use effect where we make our request in this fetch chords, Let's wrap this stuff in a try-catch. So I'm going to grab that, cut it, and then open up a try-catch block, and then put that in the try. Now, we want to check the response here. And if the results array has nothing in it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Geocoding and Mapbox map16m 40s
-
(Locked)
Handle geocode error4m 4s
-
(Locked)
Property page cleanup6m 11s
-
(Locked)
Bookmark API route10m 28s
-
(Locked)
Bookmark button request8m 27s
-
(Locked)
Bookmark status and button toggle8m 54s
-
(Locked)
Saved properties page12m 17s
-
(Locked)
Share buttons10m 41s
-
(Locked)
-
-
-