Skip to content

Commit bc3a02b

Browse files
committed
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.
1 parent 703567f commit bc3a02b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/server.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,13 @@ func setupRouter(dbPath string, logFile string) *gin.Engine {
294294
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
295295
return
296296
}
297-
c.IndentedJSON(http.StatusOK, result)
297+
if len(result) != 0 {
298+
c.IndentedJSON(http.StatusOK, result)
299+
return
300+
} else {
301+
c.JSON(http.StatusOK, gin.H{})
302+
}
303+
298304
} else {
299305
command.Uuid = c.Param("path")
300306
result, err := command.commandGetUUID()

0 commit comments

Comments
 (0)