From a84d3dc9fcbf9d4cb488b349a9c174f2b120ba99 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 7 Mar 2021 21:27:47 -0500 Subject: [PATCH] Add error to json response --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 92be0c2..0b4ba8d 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ var ( type response struct { Success bool `json:"success"` + Error error `json:"error,omitempty"` MatchedRules yara.MatchRules `json:"rules,omitempty"` } @@ -168,8 +169,7 @@ func scanHandler(w http.ResponseWriter, r *http.Request) { log.WithField("match", m).Debug("Matched rules") if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) + json.NewEncoder(w).Encode(response{Success: false, Error: err}) } else { json.NewEncoder(w).Encode(response{Success: true, MatchedRules: *m}) }