Skip to content

Commit

Permalink
internal/server: fix null search response error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nicksherron committed Feb 19, 2020
1 parent 703567f commit bc3a02b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bc3a02b

Please sign in to comment.