From 56a712a8e3dfc1b3dabbb005b42a06704415f009 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Mon, 2 Mar 2015 17:04:05 -0800 Subject: [PATCH] Queries for a measurement that doesn't exist should return a `200 OK` --- httpd/handler.go | 6 ++++++ httpd/handler_test.go | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/httpd/handler.go b/httpd/handler.go index c358c0a251..5f40a92a2a 100644 --- a/httpd/handler.go +++ b/httpd/handler.go @@ -417,11 +417,17 @@ func isAuthorizationError(err error) bool { return ok } +func isMeasurementNotFoundError(err error) bool { + return (err.Error() == "measurement not found") +} + // httpResult writes a Results array to the client. func httpResults(w http.ResponseWriter, results influxdb.Results, pretty bool) { if results.Error() != nil { if isAuthorizationError(results.Error()) { w.WriteHeader(http.StatusUnauthorized) + } else if isMeasurementNotFoundError(results.Error()) { + w.WriteHeader(http.StatusOK) } else { w.WriteHeader(http.StatusInternalServerError) } diff --git a/httpd/handler_test.go b/httpd/handler_test.go index 1aa2cdf951..29fbe85f06 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -252,6 +252,29 @@ func TestHandler_DropDatabase_NotFound(t *testing.T) { } } +func TestHandler_SelectMeasurement_NotFound(t *testing.T) { + srvr := OpenAuthlessServer(NewMessagingClient()) + srvr.CreateDatabase("foo") + s := NewHTTPServer(srvr) + defer s.Close() + + query := map[string]string{"q": "CREATE RETENTION POLICY bar ON foo DURATION 1h REPLICATION 1 DEFAULT"} + status, body := MustHTTP("GET", s.URL+`/query`, query, nil, "") + + if status != http.StatusOK { + t.Fatalf("unexpected status: %d", status) + } else if body != `{"results":[{}]}` { + t.Fatalf("unexpected body: %s", body) + } + + status, body = MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "SELECT value FROM foobarbaz", "db": "foo"}, nil, "") + if status != http.StatusOK { + t.Fatalf("unexpected status: %d", status) + } else if body != `{"results":[{"error":"measurement not found"}]}` { + t.Fatalf("unexpected body: %s", body) + } +} + func TestHandler_RetentionPolicies(t *testing.T) { srvr := OpenAuthlessServer(NewMessagingClient()) srvr.CreateDatabase("foo")