mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Improve error handling when the response is empty
This commit is contained in:
parent
1e70ca1a19
commit
0fb87eba3f
5 changed files with 28 additions and 6 deletions
|
@ -69,7 +69,10 @@ func parseFeed(r io.Reader) (*model.Feed, error) {
|
|||
defer timer.ExecutionTime(time.Now(), "[Feed:ParseFeed]")
|
||||
|
||||
var buffer bytes.Buffer
|
||||
io.Copy(&buffer, r)
|
||||
size, _ := io.Copy(&buffer, r)
|
||||
if size == 0 {
|
||||
return nil, errors.New("This feed is empty")
|
||||
}
|
||||
|
||||
reader := bytes.NewReader(buffer.Bytes())
|
||||
format := DetectFeedFormat(reader)
|
||||
|
|
|
@ -205,3 +205,10 @@ func TestParseUnknownFeed(t *testing.T) {
|
|||
t.Error("ParseFeed must returns an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEmptyFeed(t *testing.T) {
|
||||
_, err := parseFeed(bytes.NewBufferString(""))
|
||||
if err == nil {
|
||||
t.Error("ParseFeed must returns an error")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue