summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-02-13 00:29:34 +0100
committerWim <wim@42.be>2019-02-13 00:29:34 +0100
commit5af1d8005509e42102b2e2c2319b1fd754bb46f3 (patch)
tree5d2673ca96f3232fbdf9f0cefc913dbbde293220
parentf236d12166a8ae186b251fee15b88d774dabc69c (diff)
downloadmatterbridge-msglm-5af1d8005509e42102b2e2c2319b1fd754bb46f3.tar.gz
matterbridge-msglm-5af1d8005509e42102b2e2c2319b1fd754bb46f3.tar.bz2
matterbridge-msglm-5af1d8005509e42102b2e2c2319b1fd754bb46f3.zip
Do not panic on non-json response from server (zulip)
-rw-r--r--bridge/zulip/zulip.go9
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--vendor/github.com/matterbridge/gozulipbot/queue.go5
-rw-r--r--vendor/modules.txt2
5 files changed, 17 insertions, 5 deletions
diff --git a/bridge/zulip/zulip.go b/bridge/zulip/zulip.go
index 165bdb18..3c6c7ec6 100644
--- a/bridge/zulip/zulip.go
+++ b/bridge/zulip/zulip.go
@@ -104,6 +104,9 @@ func (b *Bzulip) handleQueue() error {
switch err {
case gzb.BackoffError:
time.Sleep(time.Second * 5)
+ case gzb.NoJSONError:
+ b.Log.Error("Response wasn't JSON, server down or restarting? sleeping 10 seconds")
+ time.Sleep(time.Second * 10)
case gzb.BadEventQueueError:
b.Log.Info("got a bad event queue id error, reconnecting")
b.bot.Queues = nil
@@ -113,10 +116,14 @@ func (b *Bzulip) handleQueue() error {
time.Sleep(time.Second * 10)
continue
}
- continue
+ case gzb.HeartbeatError:
+ b.Log.Debug("heartbeat received.")
default:
b.Log.Debugf("receiving error: %#v", err)
}
+ if err != nil {
+ continue
+ }
for _, m := range messages {
b.Log.Debugf("== Receiving %#v", m)
// ignore our own messages
diff --git a/go.mod b/go.mod
index dc3d0fb5..ce7c3cc0 100644
--- a/go.mod
+++ b/go.mod
@@ -25,7 +25,7 @@ require (
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 // indirect
github.com/matterbridge/go-xmpp v0.0.0-20180529212104-cd19799fba91
github.com/matterbridge/gomatrix v0.0.0-20190102230110-6f9631ca6dea
- github.com/matterbridge/gozulipbot v0.0.0-20190211002717-befe50663a92
+ github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18
github.com/matterbridge/logrus-prefixed-formatter v0.0.0-20180806162718-01618749af61
github.com/mattermost/mattermost-server v5.5.0+incompatible
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
diff --git a/go.sum b/go.sum
index 6403ebd7..04ac0b22 100644
--- a/go.sum
+++ b/go.sum
@@ -70,8 +70,8 @@ github.com/matterbridge/go-xmpp v0.0.0-20180529212104-cd19799fba91 h1:KzDEcy8eDb
github.com/matterbridge/go-xmpp v0.0.0-20180529212104-cd19799fba91/go.mod h1:ECDRehsR9TYTKCAsRS8/wLeOk6UUqDydw47ln7wG41Q=
github.com/matterbridge/gomatrix v0.0.0-20190102230110-6f9631ca6dea h1:kaADGqpK4gGO2BpzEyJrBxq2Jc57Rsar4i2EUxcACUc=
github.com/matterbridge/gomatrix v0.0.0-20190102230110-6f9631ca6dea/go.mod h1:+jWeaaUtXQbBRdKYWfjW6JDDYiI2XXE+3NnTjW5kg8g=
-github.com/matterbridge/gozulipbot v0.0.0-20190211002717-befe50663a92 h1:4L4vltV2H74Wl+fuwH3xDBe5jvFTn85UXdTqkCPs6Mg=
-github.com/matterbridge/gozulipbot v0.0.0-20190211002717-befe50663a92/go.mod h1:yAjnZ34DuDyPHMPHHjOsTk/FefW4JJjoMMCGt/8uuQA=
+github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18 h1:fLhwXtWGtfTgZVxHG1lcKjv+re7dRwyyuYFNu69xdho=
+github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18/go.mod h1:yAjnZ34DuDyPHMPHHjOsTk/FefW4JJjoMMCGt/8uuQA=
github.com/matterbridge/logrus-prefixed-formatter v0.0.0-20180806162718-01618749af61 h1:R/MgM/eUyRBQx2FiH6JVmXck8PaAuKfe2M1tWIzW7nE=
github.com/matterbridge/logrus-prefixed-formatter v0.0.0-20180806162718-01618749af61/go.mod h1:iXGEotOvwI1R1SjLxRc+BF5rUORTMtE0iMZBT2lxqAU=
github.com/mattermost/mattermost-server v5.5.0+incompatible h1:0wcLGgYtd+YImtLDPf2AOfpBHxbU4suATx+6XKw1XbU=
diff --git a/vendor/github.com/matterbridge/gozulipbot/queue.go b/vendor/github.com/matterbridge/gozulipbot/queue.go
index af32bb6e..d6e910ee 100644
--- a/vendor/github.com/matterbridge/gozulipbot/queue.go
+++ b/vendor/github.com/matterbridge/gozulipbot/queue.go
@@ -1,6 +1,7 @@
package gozulipbot
import (
+ "bytes"
"encoding/json"
"fmt"
"io/ioutil"
@@ -18,6 +19,7 @@ var (
BackoffError = fmt.Errorf("Too many requests")
BadEventQueueError = fmt.Errorf("BAD_EVENT_QUEUE_ID error")
UnknownError = fmt.Errorf("Error was unknown")
+ NoJSONError = fmt.Errorf("No JSON in body found")
)
type Queue struct {
@@ -150,6 +152,9 @@ func (q *Queue) GetEvents() ([]EventMessage, error) {
case resp.StatusCode == 403:
return nil, UnauthorizedError
case resp.StatusCode >= 400:
+ if bytes.HasPrefix(body, []byte("<")) {
+ return nil, NoJSONError
+ }
qErr, err := q.ParseError(body)
if err != nil || qErr == nil {
return nil, UnknownError
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 1b268fcb..d01d5147 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -70,7 +70,7 @@ github.com/magiconair/properties
github.com/matterbridge/go-xmpp
# github.com/matterbridge/gomatrix v0.0.0-20190102230110-6f9631ca6dea
github.com/matterbridge/gomatrix
-# github.com/matterbridge/gozulipbot v0.0.0-20190211002717-befe50663a92
+# github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18
github.com/matterbridge/gozulipbot
# github.com/matterbridge/logrus-prefixed-formatter v0.0.0-20180806162718-01618749af61
github.com/matterbridge/logrus-prefixed-formatter