From 150d34705399c7c2470abf905ff8ba4a5c2789da Mon Sep 17 00:00:00 2001 From: Gabriel Simmer Date: Thu, 7 Jul 2022 18:28:09 +0100 Subject: [PATCH] Return 404 and empty json for routes --- transport/http.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/transport/http.go b/transport/http.go index acb902b..2d92daf 100644 --- a/transport/http.go +++ b/transport/http.go @@ -253,6 +253,11 @@ func (h *Handler) Servers(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } + if len(servers) == 0 { + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("[]")) + return + } json.NewEncoder(w).Encode(servers) return } @@ -351,6 +356,12 @@ func (h *Handler) ServerInvites(w http.ResponseWriter, r *http.Request) { return } + if len(serverInvites) == 0 { + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("[]")) + return + } + json.NewEncoder(w).Encode(serverInvites) return } @@ -372,6 +383,12 @@ func (h *Handler) InviteLog(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } + if len(logs) == 0 { + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("[]")) + return + } + json.NewEncoder(w).Encode(logs) }