Fix crash on invalid playlist URL
This commit is contained in:
parent
00fb7ff05a
commit
7c57cbc3d9
|
@ -37,13 +37,15 @@ func NewPlaylist(user, id string) (*Playlist, error) {
|
||||||
|
|
||||||
if response, err := http.Get(jsonUrl); err == nil {
|
if response, err := http.Get(jsonUrl); err == nil {
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
if response.StatusCode != 400 {
|
if response.StatusCode != 400 && response.StatusCode != 404 {
|
||||||
if body, err := ioutil.ReadAll(response.Body); err == nil {
|
if body, err := ioutil.ReadAll(response.Body); err == nil {
|
||||||
jsonString = string(body)
|
jsonString = string(body)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("Invalid YouTube ID supplied.")
|
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{}{}
|
jsonData := map[string]interface{}{}
|
||||||
|
|
4
song.go
4
song.go
|
@ -39,13 +39,15 @@ func NewSong(user, id string) (*Song, error) {
|
||||||
|
|
||||||
if response, err := http.Get(jsonUrl); err == nil {
|
if response, err := http.Get(jsonUrl); err == nil {
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
if response.StatusCode != 400 {
|
if response.StatusCode != 400 && response.StatusCode != 404 {
|
||||||
if body, err := ioutil.ReadAll(response.Body); err == nil {
|
if body, err := ioutil.ReadAll(response.Body); err == nil {
|
||||||
jsonString = string(body)
|
jsonString = string(body)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("Invalid YouTube ID supplied.")
|
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{}{}
|
jsonData := map[string]interface{}{}
|
||||||
|
|
Reference in a new issue