From bc3a02bd066abd8bbae5c0305ca06f68bd2512f2 Mon Sep 17 00:00:00 2001 From: nicksherron Date: Wed, 19 Feb 2020 14:42:48 -0500 Subject: [PATCH] internal/server: fix null search response error A command search with 0 results would return null and cause the client to throw an error because of invalid json. For example, "bh 'some non-existent-command'" would respond with "Sorry, an error occurred communicating with Bashhub. Response Code: 200" A zero result response now returns {} which the bashhub-client doesn't complain about. --- internal/server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/server.go b/internal/server.go index 424ef04..1dc3d10 100644 --- a/internal/server.go +++ b/internal/server.go @@ -294,7 +294,13 @@ func setupRouter(dbPath string, logFile string) *gin.Engine { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } - c.IndentedJSON(http.StatusOK, result) + if len(result) != 0 { + c.IndentedJSON(http.StatusOK, result) + return + } else { + c.JSON(http.StatusOK, gin.H{}) + } + } else { command.Uuid = c.Param("path") result, err := command.commandGetUUID()