Skip to content

Commit

Permalink
[inkio/net.go] added GET response status code + status message in err…
Browse files Browse the repository at this point in the history
…or messages for all non-200 responses
  • Loading branch information
chrissimpkins committed Dec 30, 2017
1 parent f0c79ee commit 9ce7387
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inkio/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func GetRequest(templateURL string) (string, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return emptystring, fmt.Errorf("%s returned a non-200 response status code value %d", templateURL, resp.StatusCode)
return emptystring, fmt.Errorf("%s returned a non-200 response status: %s", templateURL, resp.Status)
}

body, _ := ioutil.ReadAll(resp.Body)
Expand Down
9 changes: 8 additions & 1 deletion inkio/net_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package inkio

import "testing"
import (
"fmt"
"strings"
"testing"
)

func TestGetRequestValidURL(t *testing.T) {
responsePointer, err := GetRequest("https://raw.githubusercontent.com/chrissimpkins/ink/master/testfiles/simpletext.txt")
Expand All @@ -20,4 +24,7 @@ func TestGetRequestInvalidURL(t *testing.T) {
if err == nil {
t.Errorf("[FAIL] GetRequest function should have returned an error on an invalid URL, instead returned nil")
}
if strings.Contains(fmt.Sprint(err), "404 Not Found") == false {
t.Errorf("[FAIL] GetRequest function should have returned 404 response status code on invalid URL to missing file")
}
}

0 comments on commit 9ce7387

Please sign in to comment.