Timelines: Handle error from API server
authorMikael Berthe <mikael@lilotux.net>
Wed, 12 Apr 2017 23:02:15 +0200
changeset 92 05c201b548b0
parent 91 ae9ad3c7bca5
child 93 d427d8aa75f9
Timelines: Handle error from API server
timelines.go
--- a/timelines.go	Wed Apr 12 22:46:16 2017 +0200
+++ b/timelines.go	Wed Apr 12 23:02:15 2017 +0200
@@ -30,6 +30,13 @@
 
 	err = json.Unmarshal([]byte(r.Body), &tl)
 	if err != nil {
+		var res struct {
+			Error string `json:"error"`
+		}
+		err2 := json.Unmarshal([]byte(r.Body), &res)
+		if err2 == nil {
+			return tl, fmt.Errorf("%s", res.Error)
+		}
 		return tl, fmt.Errorf("timelines API: %s", err.Error())
 	}