Use Error entity structure
authorMikael Berthe <mikael@lilotux.net>
Thu, 13 Apr 2017 00:17:57 +0200
changeset 98 5d803adfc57e
parent 97 1d5879af2556
child 99 6ec2a44a1bd1
Use Error entity structure
favourites.go
notifications.go
timelines.go
--- a/favourites.go	Thu Apr 13 00:00:00 2017 +0200
+++ b/favourites.go	Thu Apr 13 00:17:57 2017 +0200
@@ -20,12 +20,10 @@
 	println(r.Body)
 	err = json.Unmarshal([]byte(r.Body), &faves)
 	if err != nil {
-		var res struct {
-			Error string `json:"error"`
-		}
-		err2 := json.Unmarshal([]byte(r.Body), &res)
+		var errorRes Error
+		err2 := json.Unmarshal([]byte(r.Body), &errorRes)
 		if err2 == nil {
-			return faves, fmt.Errorf("%s", res.Error)
+			return faves, fmt.Errorf("%s", errorRes.Text)
 		}
 		return faves, fmt.Errorf("favourites API: %s", err.Error())
 	}
--- a/notifications.go	Thu Apr 13 00:00:00 2017 +0200
+++ b/notifications.go	Thu Apr 13 00:17:57 2017 +0200
@@ -20,12 +20,10 @@
 
 	err = json.Unmarshal([]byte(r.Body), &notifications)
 	if err != nil {
-		var res struct {
-			Error string `json:"error"`
-		}
-		err2 := json.Unmarshal([]byte(r.Body), &res)
+		var errorRes Error
+		err2 := json.Unmarshal([]byte(r.Body), &errorRes)
 		if err2 == nil {
-			return notifications, fmt.Errorf("%s", res.Error)
+			return notifications, fmt.Errorf("%s", errorRes.Text)
 		}
 		return notifications, fmt.Errorf("notifications API: %s", err.Error())
 	}
@@ -45,12 +43,10 @@
 
 	err = json.Unmarshal([]byte(r.Body), &notification)
 	if err != nil {
-		var res struct {
-			Error string `json:"error"`
-		}
-		err2 := json.Unmarshal([]byte(r.Body), &res)
+		var errorRes Error
+		err2 := json.Unmarshal([]byte(r.Body), &errorRes)
 		if err2 == nil {
-			return &notification, fmt.Errorf("%s", res.Error)
+			return &notification, fmt.Errorf("%s", errorRes.Text)
 		}
 		return &notification, fmt.Errorf("notification API: %s", err.Error())
 	}
--- a/timelines.go	Thu Apr 13 00:00:00 2017 +0200
+++ b/timelines.go	Thu Apr 13 00:17:57 2017 +0200
@@ -34,12 +34,10 @@
 
 	err = json.Unmarshal([]byte(r.Body), &tl)
 	if err != nil {
-		var res struct {
-			Error string `json:"error"`
-		}
-		err2 := json.Unmarshal([]byte(r.Body), &res)
+		var errorRes Error
+		err2 := json.Unmarshal([]byte(r.Body), &errorRes)
 		if err2 == nil {
-			return tl, fmt.Errorf("%s", res.Error)
+			return tl, fmt.Errorf("%s", errorRes.Text)
 		}
 		return tl, fmt.Errorf("timelines API: %s", err.Error())
 	}