From 91bf3f8cdb1512f9ed7ad33a23070317520efc9c Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Fri, 3 Apr 2020 13:51:24 +0200 Subject: [PATCH] Improve GetDetails and Search We now use the right log object with prefix and return an error on GetDetails only if the error is Fatal --- backend/movies/movies.go | 7 +++++-- backend/shows/episodes.go | 7 +++++-- backend/shows/handlers.go | 6 ++++-- backend/shows/shows.go | 7 +++++-- go.mod | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/backend/movies/movies.go b/backend/movies/movies.go index 03038ea..017a27e 100644 --- a/backend/movies/movies.go +++ b/backend/movies/movies.go @@ -11,6 +11,7 @@ import ( "git.quimbo.fr/odwrtw/canape/backend/models" "git.quimbo.fr/odwrtw/canape/backend/subtitles" "git.quimbo.fr/odwrtw/canape/backend/web" + "github.com/odwrtw/errors" "github.com/odwrtw/papi" polochon "github.com/odwrtw/polochon/lib" "github.com/sirupsen/logrus" @@ -97,9 +98,11 @@ func (m *Movie) GetDetails(env *web.Env, detailers []polochon.Detailer) error { m.Detailers = detailers // GetDetail - err := polochon.GetDetails(m.Movie, env.Log) + err := polochon.GetDetails(m.Movie, log) if err != nil { - return err + if errors.IsFatal(err) { + return err + } } log.Debug("got details from detailers") diff --git a/backend/shows/episodes.go b/backend/shows/episodes.go index 4809d45..dce9854 100644 --- a/backend/shows/episodes.go +++ b/backend/shows/episodes.go @@ -8,6 +8,7 @@ import ( "git.quimbo.fr/odwrtw/canape/backend/models" "git.quimbo.fr/odwrtw/canape/backend/subtitles" "git.quimbo.fr/odwrtw/canape/backend/web" + "github.com/odwrtw/errors" "github.com/odwrtw/papi" polochon "github.com/odwrtw/polochon/lib" "github.com/sirupsen/logrus" @@ -211,9 +212,11 @@ func (e *Episode) GetEpisodeDetails(env *web.Env, detailers []polochon.Detailer) e.ShowEpisode.Detailers = detailers // Get the details - err := polochon.GetDetails(e.ShowEpisode, env.Log) + err := polochon.GetDetails(e.ShowEpisode, log) if err != nil { - return err + if errors.IsFatal(err) { + return err + } } log.Debug("got details from detailers") diff --git a/backend/shows/handlers.go b/backend/shows/handlers.go index 65ba5d7..bd3ca90 100644 --- a/backend/shows/handlers.go +++ b/backend/shows/handlers.go @@ -128,11 +128,13 @@ func SearchShow(env *web.Env, w http.ResponseWriter, r *http.Request) error { searchers := env.Config.Show.Searchers // Iterate on all the searchers to search for the show for _, searcher := range searchers { - result, err := searcher.SearchShow(search, env.Log) + log := env.Log.WithField("searcher", searcher.Name()) + result, err := searcher.SearchShow(search, log) if err != nil { - env.Log.Errorf("error while searching show : %s", err) + log.Errorf("error while searching show : %s", err) continue } + log.Debug("found show") // Add the results to the list of results shows = append(shows, result...) } diff --git a/backend/shows/shows.go b/backend/shows/shows.go index 9733895..4101416 100644 --- a/backend/shows/shows.go +++ b/backend/shows/shows.go @@ -9,6 +9,7 @@ import ( "git.quimbo.fr/odwrtw/canape/backend/models" "git.quimbo.fr/odwrtw/canape/backend/web" + "github.com/odwrtw/errors" "github.com/odwrtw/papi" polochon "github.com/odwrtw/polochon/lib" "github.com/sirupsen/logrus" @@ -95,9 +96,11 @@ func (s *Show) GetDetails(env *web.Env, detailers []polochon.Detailer) error { s.Detailers = detailers // Get the details - err := polochon.GetDetails(s.Show, env.Log) + err := polochon.GetDetails(s.Show, log) if err != nil { - return err + if errors.IsFatal(err) { + return err + } } log.Debugf("got details from detailers") diff --git a/go.mod b/go.mod index 49d1cdc..34e91c1 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/lib/pq v1.1.1 github.com/mattn/go-sqlite3 v1.10.0 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 + github.com/odwrtw/errors v0.0.0-20170604160533-c747b9d17833 github.com/odwrtw/papi v0.0.0-20190511132159-936937ad8b6a github.com/odwrtw/polochon v0.0.0-20200131104911-522892bdd053 github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029