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.
This commit is contained in:
nicksherron 2020-02-19 14:42:48 -05:00
parent 703567f19c
commit bc3a02bd06

View file

@ -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()