Commit 6dc3680b authored by zauberstuhl's avatar zauberstuhl

Add error handling to relay registration

This way we can better track whether
the pod was successfully registered

requires https://github.com/thefederationinfo/the-federation.info/pull/162
parent 29159a49
Pipeline #661 passed with stages
in 9 minutes and 57 seconds
......@@ -73,14 +73,47 @@ func InitSocialRelay() {
// this is required for using the social-relay
revel.Config.SetSection("ganggo")
subscribe := revel.Config.BoolDefault("relay.subscribe", false)
if !revel.DevMode && subscribe {
address, found := revel.Config.String("address")
if found {
_, err := http.Get("https://the-federation.info/register/" + address)
if err != nil {
revel.WARN.Println("Wasn't able to register at the-federation.info", err)
}
address := revel.Config.StringDefault("address", "")
if !revel.DevMode && address != "" && subscribe {
endpoint := revel.Config.StringDefault(
"relay.info", "https://the-federation.info")
req, err := http.NewRequest("GET", endpoint + "/register/" + address, nil)
if err != nil {
revel.AppLog.Error("InitSocialRelay", "error", err)
return
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
revel.AppLog.Error("InitSocialRelay", "error", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
revel.AppLog.Error("InitSocialRelay", "error", err)
return
}
respInt := struct{Error string `json:"error"`}{}
err = json.Unmarshal(body, &respInt)
if err != nil {
revel.AppLog.Error("InitSocialRelay", "error", err)
return
}
if respInt.Error != "" {
revel.AppLog.Error("InitSocialRelay", "error", respInt.Error)
} else {
revel.AppLog.Info("Succesfully registered!", "endpoint", endpoint)
}
} else {
revel.AppLog.Debug("Skipping relay registration",
"devMode", revel.DevMode, "address", address, "subscribe", subscribe)
}
}
......
......@@ -51,6 +51,13 @@ relay.subscribe = false
#relay.scope = "all"
# This option is obsolete if you specified "all" in "relay.scope"
#relay.tags = "social,network,politics"
# GangGo was tested against the-federation.info
# Only change 'relay.info' if you really know what you are doing!
#relay.info = "https://the-federation.info"
# Open-source error tracking that helps developers monitor and
# fix crashes in real time (see https://sentry.io)
#sentry.DSN = ""
[DEFAULT]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment