You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/11/03 21:53:25 UTC

[GitHub] [trafficcontrol] srijeet0406 commented on a change in pull request #5231: Fix service categories if-not-modified/if-match functionality

srijeet0406 commented on a change in pull request #5231:
URL: https://github.com/apache/trafficcontrol/pull/5231#discussion_r516973306



##########
File path: traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go
##########
@@ -149,14 +135,18 @@ func Update(w http.ResponseWriter, r *http.Request) {
 	}
 
 	var origSC TOServiceCategory
-	if err := inf.Tx.QueryRow(`SELECT name FROM service_category WHERE name = $1`, name).Scan(&origSC.Name); err != nil {
+	if err := inf.Tx.QueryRow(`SELECT name, last_updated FROM service_category WHERE name = $1`, name).Scan(&origSC.Name, &origSC.LastUpdated); err != nil {
 		if err == sql.ErrNoRows {
 			api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, errors.New("no service category found with name "+name), nil)
 			return
 		}
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
 		return
 	}
+	if !api.IsUnmodified(r.Header, origSC.LastUpdated.Time) {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusPreconditionFailed, errors.New("service category has been modified"), nil)

Review comment:
       The API error should not be "service category has been modified", rather it should be something like "service category could not be modified because the precondition failed", or something to that effect.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org