Queries for a measurement that doesn't exist should return a `200 OK`

pull/1813/head
Todd Persen 2015-03-02 17:04:05 -08:00
parent c53cd6b392
commit 56a712a8e3
2 changed files with 29 additions and 0 deletions

View File

@ -417,11 +417,17 @@ func isAuthorizationError(err error) bool {
return ok return ok
} }
func isMeasurementNotFoundError(err error) bool {
return (err.Error() == "measurement not found")
}
// httpResult writes a Results array to the client. // httpResult writes a Results array to the client.
func httpResults(w http.ResponseWriter, results influxdb.Results, pretty bool) { func httpResults(w http.ResponseWriter, results influxdb.Results, pretty bool) {
if results.Error() != nil { if results.Error() != nil {
if isAuthorizationError(results.Error()) { if isAuthorizationError(results.Error()) {
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
} else if isMeasurementNotFoundError(results.Error()) {
w.WriteHeader(http.StatusOK)
} else { } else {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
} }

View File

@ -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) { func TestHandler_RetentionPolicies(t *testing.T) {
srvr := OpenAuthlessServer(NewMessagingClient()) srvr := OpenAuthlessServer(NewMessagingClient())
srvr.CreateDatabase("foo") srvr.CreateDatabase("foo")