fix: handle no results
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user