1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Improve error handling when the response is empty

This commit is contained in:
Frédéric Guillot 2018-02-07 18:47:47 -08:00
parent 1e70ca1a19
commit 0fb87eba3f
5 changed files with 28 additions and 6 deletions

View file

@ -23,6 +23,7 @@ import (
var (
errConnectionFailure = "Unable to open this link: %v"
errUnreadableDoc = "Unable to analyze this page: %v"
errEmptyBody = "This web page is empty"
)
// FindSubscriptions downloads and try to find one or more subscriptions from an URL.
@ -35,13 +36,22 @@ func FindSubscriptions(websiteURL string) (Subscriptions, error) {
return nil, errors.NewLocalizedError(errConnectionFailure, err)
}
// Content-Length = -1 when no Content-Length header is sent
if response.ContentLength == 0 {
return nil, errors.NewLocalizedError(errEmptyBody)
}
body, err := response.NormalizeBodyEncoding()
if err != nil {
return nil, err
}
var buffer bytes.Buffer
io.Copy(&buffer, body)
size, _ := io.Copy(&buffer, body)
if size == 0 {
return nil, errors.NewLocalizedError(errEmptyBody)
}
reader := bytes.NewReader(buffer.Bytes())
if format := feed.DetectFeedFormat(reader); format != feed.FormatUnknown {