Skip to content

Commit

Permalink
fixing the logic for asn-update for v5
Browse files Browse the repository at this point in the history
  • Loading branch information
rimashah25 committed Aug 31, 2023
1 parent e835435 commit 6a4217d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions traffic_ops/traffic_ops_golang/asn/asns.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ func Update(w http.ResponseWriter, r *http.Request) {
}

// check if asn already exists
var count int
err := tx.QueryRow("SELECT count(*) from asn where asn=$1", asn.ASN).Scan(&count)
if err != nil {
var id int
err := tx.QueryRow("SELECT id from asn where asn=$1", asn.ASN).Scan(&id)
if err != nil && err != sql.ErrNoRows {
api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("error: %w, when checking if asn '%d' exists", err, asn.ASN))
return
}
if count == 1 {
if id != 0 && id != requestedAsnId {
api.HandleErr(w, r, tx, http.StatusBadRequest, fmt.Errorf("asn:'%d' already exists", asn.ASN), nil)
return
}
Expand Down

0 comments on commit 6a4217d

Please sign in to comment.