Add error to json response
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tyler 2021-03-07 21:27:47 -05:00
parent 4c24c0f528
commit a84d3dc9fc

View File

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