Add error to json response
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4c24c0f528
commit
a84d3dc9fc
4
main.go
4
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})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user