From 0775674f54a715806a488c939bb02530a78bdb85 Mon Sep 17 00:00:00 2001 From: Ricky Barillas <8647805+jbonzo@users.noreply.github.com> Date: Wed, 3 Nov 2021 17:41:51 -0400 Subject: [PATCH] handle error off of update by id on process errand (#16) * handle error off of update by id on process errand * Update errands-routes.go Co-authored-by: Michael Moghaddam <6424916+mmoghaddam385@users.noreply.github.com> Co-authored-by: Michael Moghaddam <6424916+mmoghaddam385@users.noreply.github.com> --- errands-routes.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/errands-routes.go b/errands-routes.go index e3039b3..2f2de63 100644 --- a/errands-routes.go +++ b/errands-routes.go @@ -223,8 +223,7 @@ func (s *ErrandsServer) processErrand(c *gin.Context) { procErrand = errands[0] - // We are processing this errand. This won't ever return error - updatedErrand, _ := s.UpdateErrandByID(procErrand.ID, func(errand *schemas.Errand) error { + updatedErrand, err := s.UpdateErrandByID(procErrand.ID, func(errand *schemas.Errand) error { errand.Started = utils.GetTimestamp() errand.Attempts++ errand.Status = schemas.StatusActive @@ -234,6 +233,15 @@ func (s *ErrandsServer) processErrand(c *gin.Context) { return nil }) + if err != nil { + log.WithError(err).Warn("potentially no job found") + + c.JSON(http.StatusNotFound, gin.H{ + "message": "No jobs", + }) + return + } + s.AddNotification("processing", updatedErrand) c.JSON(http.StatusOK, gin.H{ "status": "OK",