handle case if page responds not ok status
This commit is contained in:
6
main.go
6
main.go
@@ -38,6 +38,12 @@ func getArticleMetadata(url string) (*ArticleMetadata, error) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
|
||||
return &ArticleMetadata{
|
||||
Title: url,
|
||||
}, nil
|
||||
}
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse page html: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user