5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-12-24 03:25:40 +00:00

Do not panic on non-json response from server (zulip)

This commit is contained in:
Wim 2019-02-13 00:29:34 +01:00
parent f236d12166
commit 5af1d80055
5 changed files with 17 additions and 5 deletions

View File

@ -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

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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

2
vendor/modules.txt vendored
View File

@ -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