aboutsummaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-02-02 06:53:12 -0800
committerChristine Dodrill <me@christine.website>2019-02-02 06:53:12 -0800
commit7bcfbc6a4da40f498af83e40c3c57ef02ec212cf (patch)
treeee224b7b08722e06d78f49bc557249891264e38f /discord
parentda3595468056f1dd04d79c908f8a65dc0c5a397f (diff)
downloadx-7bcfbc6a4da40f498af83e40c3c57ef02ec212cf.tar.xz
x-7bcfbc6a4da40f498af83e40c3c57ef02ec212cf.zip
web: use error type, simplify some code
Diffstat (limited to 'discord')
-rw-r--r--discord/ilo-kesi/main.go3
-rw-r--r--discord/ilo-kesi/parse.go10
2 files changed, 7 insertions, 6 deletions
diff --git a/discord/ilo-kesi/main.go b/discord/ilo-kesi/main.go
index 49d4f2c..ce15aa3 100644
--- a/discord/ilo-kesi/main.go
+++ b/discord/ilo-kesi/main.go
@@ -5,7 +5,6 @@ import (
"fmt"
"log"
"math/rand"
- "net/http"
"os"
"os/signal"
"regexp"
@@ -51,7 +50,7 @@ func main() {
}
cfg.JanLawa = append(cfg.JanLawa, "console")
- sw := switchcounter.NewHTTPClient(http.DefaultClient, cfg.SwitchCounterWebhook)
+ sw := switchcounter.NewHTTPClient(cfg.SwitchCounterWebhook)
line := liner.NewLiner()
defer line.Close()
diff --git a/discord/ilo-kesi/parse.go b/discord/ilo-kesi/parse.go
index f945e39..c54f9c4 100644
--- a/discord/ilo-kesi/parse.go
+++ b/discord/ilo-kesi/parse.go
@@ -53,8 +53,9 @@ func (i ilo) parse(authorID, inp string) (*reply, error) {
if err != nil {
return nil, err
}
- if resp.StatusCode/100 != 2 {
- return nil, errors.New(resp.Status)
+ err = switchcounter.Validate(resp)
+ if err != nil {
+ return nil, err
}
var st switchcounter.Status
err = json.NewDecoder(resp.Body).Decode(&st)
@@ -78,8 +79,9 @@ func (i ilo) parse(authorID, inp string) (*reply, error) {
if err != nil {
return nil, err
}
- if resp.StatusCode/100 != 2 {
- return nil, errors.New(resp.Status)
+ err = switchcounter.Validate(resp)
+ if err != nil {
+ return nil, err
}
fmt.Fprintf(buf, "tenpo ni la jan %s li lawa insa.\n", req.Subject)