From d4964c845007e2a0ca1dc07dc78876fa39ed3d16 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Thu, 25 Sep 2014 13:27:05 +0100 Subject: [PATCH] Added specific error types rather than generic error types --- feed.go | 13 ++++++++++--- rss.go | 8 +++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/feed.go b/feed.go index 8046520..1a03408 100644 --- a/feed.go +++ b/feed.go @@ -26,7 +26,6 @@ package feeder import ( - "errors" "fmt" xmlx "github.com/jteeuwen/go-pkg-xmlx" "net/http" @@ -35,6 +34,15 @@ import ( "time" ) +type UnsupportedFeedError struct { + Type string + Version [2]int +} + +func (err *UnsupportedFeedError) Error() string { + return fmt.Sprintf("Unsupported feed: %s, version: %+v", err.Type, err.Version) +} + type ChannelHandler func(f *Feed, newchannels []*Channel) type ItemHandler func(f *Feed, ch *Channel, newitems []*Item) @@ -150,8 +158,7 @@ func (this *Feed) makeFeed(doc *xmlx.Document) (err error) { this.Type, this.Version = this.GetVersionInfo(doc) if ok := this.testVersions(); !ok { - err = errors.New(fmt.Sprintf("Unsupported feed: %s, version: %+v", this.Type, this.Version)) - return + return &UnsupportedFeedError{Type: this.Type, Version: this.Version} } if err = this.buildFeed(doc); err != nil || len(this.Channels) == 0 { diff --git a/rss.go b/rss.go index 1c347ca..cefec26 100644 --- a/rss.go +++ b/rss.go @@ -1,11 +1,13 @@ package feeder import ( - "errors" - xmlx "github.com/jteeuwen/go-pkg-xmlx" ) +type MissingRssNodeError struct{} + +func (err *MissingRssNodeError) Error() string { return "Failed to find rss/rdf node in XML." } + type Extension struct { Name string Value string @@ -37,7 +39,7 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) { } if root == nil { - return errors.New("Failed to find rss/rdf node in XML.") + return &MissingRssNodeError{} } channels := root.SelectNodes(ns, "channel")