treat status != 200 as error - twitch-go - twitch.tv web application in Go
HTML git clone git://git.codemadness.org/twitch-go
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 2481cef0e92b8deb9eebc43881f397843991bcfd
DIR parent 05d370c0b80ab9f2c75c8533782e63cf65b2e6a7
HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 6 Nov 2016 19:43:50 +0100
treat status != 200 as error
Diffstat:
M data/templates/pages/featured.html | 2 +-
M src/twitch/twitch.go | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
---
DIR diff --git a/data/templates/pages/featured.html b/data/templates/pages/featured.html
@@ -14,7 +14,7 @@
</tr>
</thead>
<tbody>
-
+
{{range .Featured }}
<tr>
<td class="game"><a href="/game?g={{.Stream.Game}}">{{.Stream.Game}}</a></td>
DIR diff --git a/src/twitch/twitch.go b/src/twitch/twitch.go
@@ -2,6 +2,7 @@ package twitch
import (
"encoding/json"
+ "errors"
"fmt"
"io/ioutil"
"net/http"
@@ -117,6 +118,9 @@ func ReadAllUrl(url string) ([]byte, error) {
if err != nil {
return nil, err
}
+ if resp.StatusCode != 200 {
+ return nil, errors.New(resp.Status)
+ }
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err