Skip to content

Commit

Permalink
fix v2 subscription
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Ding <jackding@gmail.com>
  • Loading branch information
jzding committed Jul 23, 2024
1 parent 2b0b52c commit 4c4da24
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions v2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ func (s *Server) createSubscription(w http.ResponseWriter, r *http.Request) {
}

if out.Data == nil {
respondWithStatusCode(w, http.StatusNotFound, "event not found")
respondWithStatusCode(w, http.StatusNotFound, fmt.Sprintf("event not found for %s", addr))
localmetrics.UpdateSubscriptionCount(localmetrics.FAILCREATE, 1)
log.Error("event not found")
return
}

Expand Down Expand Up @@ -424,7 +423,10 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) {
respondWithError(w, "resourceAddress parameter not found")
return
}

if resourceAddress == "" {
respondWithError(w, "resourceAddress can not be empty")
return
}
//identify publisher or subscriber is asking for status
var sub *pubsub.PubSub
if len(s.pubSubAPI.GetSubscriptions()) > 0 {
Expand All @@ -442,19 +444,15 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) {
}
}
} else {
respondWithStatusCode(w, http.StatusNotFound, "subscription not found")
respondWithStatusCode(w, http.StatusNotFound, "no subscription data available")
return
}

if sub == nil {
respondWithStatusCode(w, http.StatusNotFound, "subscription not found")
respondWithStatusCode(w, http.StatusNotFound, fmt.Sprintf("subscription not found for %s", resourceAddress))
return
}

if resourceAddress == "" {
_ = json.NewEncoder(w).Encode(map[string]string{"message": "validation failed, resource is empty"})
}

if !strings.HasPrefix(resourceAddress, "/") {
resourceAddress = fmt.Sprintf("/%s", resourceAddress)
}
Expand All @@ -475,7 +473,7 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) {
} else if out.Data != nil {
respondWithJSON(w, http.StatusOK, *out.Data)
} else {
respondWithStatusCode(w, http.StatusNotFound, "event not found")
respondWithStatusCode(w, http.StatusNotFound, fmt.Sprintf("event not found for %s", resourceAddress))
}
} else {
respondWithStatusCode(w, http.StatusNotFound, "onReceive function not defined")
Expand Down

0 comments on commit 4c4da24

Please sign in to comment.