diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 65509ca..6cbf902 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -44,6 +44,7 @@ func (app *application) generateRss(w http.ResponseWriter, r *http.Request) { feed := feedInfo.GenerateRSS() data := newTemplateData(r) + data.Errors = feedInfo.Errors data.Feeds = append(data.Feeds, feed) app.renderElem(w, http.StatusOK, "feed-output.tmpl.html", data) } diff --git a/cmd/web/templates.go b/cmd/web/templates.go index 44ea304..b280139 100644 --- a/cmd/web/templates.go +++ b/cmd/web/templates.go @@ -11,6 +11,7 @@ type templateData struct { CurrentYear int Feeds []string Title string + Errors map[string]string } func newTemplateCache() (map[string]*template.Template, error) { diff --git a/feed/feed.go b/feed/feed.go index aa08611..83bdc26 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -36,7 +36,7 @@ type FeedInfo struct { SiteDesc string PageUrls []string Items []*FeedItem - errors map[string]error + Errors map[string]string } type FeedItem struct { @@ -99,7 +99,7 @@ func getHtmlElement(doc *html.Node, tag string) (*html.Node, error) { } f(doc, tag) if element == nil { - return nil, fmt.Errorf("no <%s> element found", tag) + return nil, fmt.Errorf("no <%s> element found", tag) } return element, nil } @@ -148,7 +148,7 @@ func NewFeedItem(url string) (*FeedItem, error) { item := FeedItem{ Url: url, } - item.ParseContent(rawhtml); + err = item.ParseContent(rawhtml); if err != nil { return nil, fmt.Errorf("Could not parse feed item: %w", err) } @@ -161,11 +161,12 @@ func NewFeedInfo(name, base_url, desc, author string, page_urls...string) (*Feed SiteUrl: base_url, SiteDesc: desc, PageUrls: page_urls, + Errors: make(map[string]string, 10), } for _,url := range info.PageUrls { item, err := NewFeedItem(url) if err != nil { - info.errors[url] = err + info.Errors[url] = err.Error() } else { info.Items = append(info.Items, item) } diff --git a/ui/html/htmx/feed-output.tmpl.html b/ui/html/htmx/feed-output.tmpl.html index 46cd98d..5ffc6e2 100644 --- a/ui/html/htmx/feed-output.tmpl.html +++ b/ui/html/htmx/feed-output.tmpl.html @@ -1,5 +1,10 @@ -{{ range .Feeds }}
+Error parsing page at {{ $url }}: {{ $error }} +
+{{end}} +{{ range .Feeds }}