From 7c57cbc3d98fcf892d6a0af8034e6cbe15dfa932 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Mon, 2 Feb 2015 19:45:17 -0800 Subject: [PATCH] Fix crash on invalid playlist URL --- playlist.go | 4 +++- song.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/playlist.go b/playlist.go index 5177a0a..aa9909d 100644 --- a/playlist.go +++ b/playlist.go @@ -37,13 +37,15 @@ func NewPlaylist(user, id string) (*Playlist, error) { if response, err := http.Get(jsonUrl); err == nil { defer response.Body.Close() - if response.StatusCode != 400 { + if response.StatusCode != 400 && response.StatusCode != 404 { if body, err := ioutil.ReadAll(response.Body); err == nil { jsonString = string(body) } } else { return nil, errors.New("Invalid YouTube ID supplied.") } + } else { + return nil, errors.New("An error occurred while receiving HTTP GET request.") } jsonData := map[string]interface{}{} diff --git a/song.go b/song.go index f31b579..33d9250 100644 --- a/song.go +++ b/song.go @@ -39,13 +39,15 @@ func NewSong(user, id string) (*Song, error) { if response, err := http.Get(jsonUrl); err == nil { defer response.Body.Close() - if response.StatusCode != 400 { + if response.StatusCode != 400 && response.StatusCode != 404 { if body, err := ioutil.ReadAll(response.Body); err == nil { jsonString = string(body) } } else { return nil, errors.New("Invalid YouTube ID supplied.") } + } else { + return nil, errors.New("An error occurred while receiving HTTP GET request.") } jsonData := map[string]interface{}{}