From 894de3424585bec35b0c58797285587e51ae382b Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Wed, 18 Mar 2015 09:29:45 -0600 Subject: [PATCH] Return status code 200 for measurement not found errors --- httpd/handler.go | 3 ++- httpd/handler_test.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/httpd/handler.go b/httpd/handler.go index 3a0c4b86d0..c8eaa196ce 100644 --- a/httpd/handler.go +++ b/httpd/handler.go @@ -440,7 +440,8 @@ func isAuthorizationError(err error) bool { } func isMeasurementNotFoundError(err error) bool { - return (err.Error() == "measurement not found") + s := err.Error() + return strings.HasPrefix(s, "measurement") && strings.HasSuffix(s, "not found") } func isFieldNotFoundError(err error) bool { diff --git a/httpd/handler_test.go b/httpd/handler_test.go index ec1b5419e6..3aba2671c7 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -136,6 +136,25 @@ func TestBatchWrite_UnmarshalRFC(t *testing.T) { } } +// Ensure that even if a measurement is not found, that the status code is still 200 +func TestHandler_ShowMeasurementsNotFound(t *testing.T) { + c := test.NewMessagingClient() + defer c.Close() + srvr := OpenAuthlessServer(c) + srvr.CreateDatabase("foo") + srvr.CreateRetentionPolicy("foo", influxdb.NewRetentionPolicy("bar")) + srvr.SetDefaultRetentionPolicy("foo", "bar") + s := NewHTTPServer(srvr) + defer s.Close() + + status, body := MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "SHOW SERIES from bin", "db": "foo"}, nil, "") + if status != http.StatusOK { + t.Fatalf("unexpected status: %d", status) + } else if body != `{"results":[{"error":"measurement \"bin\" not found"}]}` { + t.Fatalf("unexpected body: %s", body) + } +} + func TestHandler_Databases(t *testing.T) { c := test.NewMessagingClient() defer c.Close()