Fix error handling

This commit is contained in:
Alex 2017-10-22 21:19:10 -04:00
parent f88983a4f7
commit a29dbdb775
2 changed files with 4 additions and 3 deletions

@ -28,7 +28,7 @@ type ScanTarget struct {
type ScanResponse struct {
Result interface{} `json:"result,omitempty"`
Time string `json:"time,omitempty"`
Error *error `json:"error,omitempty"`
Error *string `json:"error,omitempty"`
ErrorComponent string `json:"error_component,omitempty"`
}

@ -30,13 +30,14 @@ func PrintScanners() {
func RunScanner(s Scanner, mon *Monitor, target ScanTarget) (string, ScanResponse) {
t := time.Now()
res, e := s.Scan(target)
var err *error //nil pointers are null in golang, which is not nil and not empty
var err *string
if e == nil {
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusSuccess}
err = nil
} else {
mon.statusesChan <- moduleStatus{name: s.GetName(), st: statusFailure}
err = &e
errString := e.Error()
err = &errString
}
resp := ScanResponse{Result: res, Error: err, Time: t.Format(time.RFC3339)}
return s.GetName(), resp