Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ErykKul committed Feb 17, 2023
1 parent fedb0cc commit 2765a08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions image/app/common/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func Compare(w http.ResponseWriter, r *http.Request) {
return
}

errMessage := config.GetRedis().Get(r.Context(), fmt.Sprintf("error %v", req.PersistentId))
if errMessage != nil && errMessage.Val() != "" {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Job failed: %v", errMessage)))
return
}

//map nodes
nm := map[string]tree.Node{}
for _, v := range req.Data {
Expand Down
2 changes: 2 additions & 0 deletions image/app/core/persisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func sendJobFailedMail(ctx context.Context, errIn error, job Job) error {
msg := fmt.Sprintf("To: %v\r\nMIME-version: 1.0;\r\nContent-Type: text/html; charset=\"UTF-8\";\r\nSubject: %v"+
"\r\n\r\n<html><body>%v</body></html>\r\n", to, getSubjectOnError(errIn, job), getContentOnError(errIn, job))
err = SendMail(msg, []string{to})
config.GetRedis().Set(ctx, fmt.Sprintf("error %v", job.PersistentId), err.Error(), FileNamesInCacheDuration)
if err != nil {
return fmt.Errorf("error when sending email on error (%v): %v", errIn, err)
}
Expand Down Expand Up @@ -230,6 +231,7 @@ func doPersistNodeMap(ctx context.Context, streams map[string]types.Stream, in J
err = ctx.Err()
return
default:
writtenKeys = append(writtenKeys, fmt.Sprintf("error %v", in.PersistentId))
err = cleanup(ctx, in.DataverseKey, in.User, in.PersistentId, writtenKeys)
}
return
Expand Down

0 comments on commit 2765a08

Please sign in to comment.