changeset 5211:8d582b5ff71e new-fwa

Some checks to prevent trivial errors.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 11 May 2020 16:18:23 +0200
parents da6eb8073f77
children 6c316a4d3386
files pkg/controllers/fwa.go
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/fwa.go	Mon May 11 16:10:26 2020 +0200
+++ b/pkg/controllers/fwa.go	Mon May 11 16:18:23 2020 +0200
@@ -223,6 +223,12 @@
 		return
 	}
 
+	// If there are no bottlenecks there is nothing to do.
+	if len(bottlenecks) == 0 {
+		http.Error(rw, "No bottlenecks found.", http.StatusNotFound)
+		return
+	}
+
 	// load validities and limiting factors
 	for i := range bottlenecks {
 		if err := bottlenecks[i].loadLimitingValidities(ctx, conn, from, to); err != nil {
@@ -242,7 +248,6 @@
 			http.Error(rw, "cannot load LDCs", http.StatusInternalServerError)
 			return
 		}
-
 	}
 
 	// separate breaks for depth and width
@@ -252,11 +257,19 @@
 	useDepth := bottlenecks.hasLimiting(limitingDepth, from, to)
 	useWidth := bottlenecks.hasLimiting(limitingWidth, from, to)
 
+	if useDepth && useWidth && len(widthbreaks) != len(depthbreaks) {
+		http.Error(
+			rw,
+			fmt.Sprintf("class breaks lengths differ: %d != %d",
+				len(widthbreaks), len(depthbreaks)),
+			http.StatusBadRequest,
+		)
+		return
+	}
+
 	// TODO: use these.
 	_ = depthbreaks
 	_ = widthbreaks
-	_ = useDepth
-	_ = useWidth
 
 	// For every day on every bottleneck we need to find out if this day is valid.
 	validities := make([]func(time.Time, time.Time) *limitingValidity, len(bottlenecks))