Fix error in unsubscriber
All checks were successful
continuous-integration/drone/push Build is passing

- wrong error checking
This commit is contained in:
Peter Stuifzand 2019-03-19 07:28:32 +01:00
parent 59668090df
commit 071bf66721

View File

@ -87,11 +87,19 @@ func (handler *subscriptionHandler) handleUnsubscription(w http.ResponseWriter,
topic := r.Form.Get("hub.topic")
mode := r.Form.Get("hub.mode")
if subscribers, err := handler.store.Subscribers(topic); err != nil {
subscribers, err := handler.store.Subscribers(topic)
if err != nil {
return errors.Wrapf(err, "could not get subscribers for %s", topic)
}
found := false
for _, subscriber := range subscribers {
if subscriber.Callback != callback {
continue
}
found = true
ourChallenge := randStringBytes(12)
validationURL, err := url.Parse(callback)
@ -113,12 +121,13 @@ func (handler *subscriptionHandler) handleUnsubscription(w http.ResponseWriter,
}
w.WriteHeader(200)
if found {
_, err = fmt.Fprintf(w, "Unsubscribed\n")
return err
} else {
http.Error(w, "Hub does not handle subscription for topic", 400)
}
return nil
return err
}
func (handler *subscriptionHandler) handleSubscription(w http.ResponseWriter, r *http.Request) error {