fix: handle no results

This commit is contained in:
2020-01-17 14:53:15 +01:00
parent ced975a3a6
commit d9381aa7e4
2 changed files with 7 additions and 5 deletions
+2
View File
@@ -1,5 +1,7 @@
module gitlab.com/unboundsoftware/dancefinder/geo-service
go 1.13
require (
github.com/caarlos0/env v3.5.0+incompatible
github.com/google/uuid v1.1.0
+5 -5
View File
@@ -150,7 +150,6 @@ func handleLatLongRequest(w http.ResponseWriter, r *http.Request, client *maps.C
Address: r.URL.Path[len("/latlong/"):],
}
if result, err := client.Geocode(context.Background(), req); err != nil {
log.Fatalf("fatal error: %s", err)
w.WriteHeader(400)
} else {
if len(result) > 0 {
@@ -159,11 +158,12 @@ func handleLatLongRequest(w http.ResponseWriter, r *http.Request, client *maps.C
Long: result[0].Geometry.Location.Lng,
}
if response, err := json.Marshal(l); err != nil {
log.Fatalf("fatal error: %s", err)
w.WriteHeader(404)
w.WriteHeader(500)
} else {
_, _ = w.Write(response)
}
}
} else {
w.WriteHeader(404)
}
}
}
}