Browse Source

Handle badness in google's API

Kirk Trombley 4 years ago
parent
commit
b388f14145
1 changed files with 10 additions and 5 deletions
  1. 10 5
      client/src/domain/geocoding.js

+ 10 - 5
client/src/domain/geocoding.js

@@ -3,13 +3,18 @@
 const GEOCODER = new google.maps.Geocoder();
 
 export const reverseGeocode = async location => {
-  const { results } = await GEOCODER.geocode({ location });
-  for (const { address_components } of results) {
-    for (const { short_name, types } of address_components) {
-      if (types.indexOf("country") >= 0) {
-        return short_name;
+  try {
+    const { results } = await GEOCODER.geocode({ location });
+    for (const { address_components } of results) {
+      for (const { short_name, types } of address_components) {
+        if (types.indexOf("country") >= 0) {
+          return short_name;
+        }
       }
     }
+  } catch (e) {
+    // ignore errors - just use null
+    // TODO probably alert the user?
   }
   return null;
 };