From 73b68c0a0ff41dc7fc93ad0645f3fd1a3ca26242 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 23 Nov 2016 14:26:59 +0900 Subject: [PATCH] Improved error handling --- api.go | 6 +++--- pages/airing/airing.go | 14 +++----------- pages/anime/anime.go | 2 +- pages/dashboard/dashboard.go | 2 +- pages/posts/posts.go | 2 +- pages/profile/profile.go | 2 +- pages/threads/threads.go | 4 ++-- 7 files changed, 12 insertions(+), 20 deletions(-) diff --git a/api.go b/api.go index 608f84b2..99b54269 100644 --- a/api.go +++ b/api.go @@ -25,7 +25,7 @@ func init() { anime, err := arn.GetAnime(id) if err != nil { - return ctx.Error(404, "Anime not found") + return ctx.Error(404, "Anime not found", err) } return ctx.JSON(anime) @@ -36,7 +36,7 @@ func init() { user, err := arn.GetUserByNick(nick) if err != nil { - return ctx.Error(404, "User not found") + return ctx.Error(404, "User not found", err) } return ctx.JSON(user) @@ -47,7 +47,7 @@ func init() { thread, err := arn.GetThread(id) if err != nil { - return ctx.Error(404, "Thread not found") + return ctx.Error(404, "Thread not found", err) } return ctx.JSON(thread) diff --git a/pages/airing/airing.go b/pages/airing/airing.go index fb6bd774..f644766d 100644 --- a/pages/airing/airing.go +++ b/pages/airing/airing.go @@ -10,20 +10,12 @@ import ( // Get ... func Get(ctx *aero.Context) string { - var animeList []*arn.Anime + animeList, err := arn.GetAiringAnime() - scan := make(chan *arn.Anime) - arn.Scan("Anime", scan) - - for anime := range scan { - if anime.AiringStatus != "currently airing" || anime.Adult { - continue - } - - animeList = append(animeList, anime) + if err != nil { + return ctx.Error(500, "Failed fetching airing anime", err) } sort.Sort(arn.AnimeByPopularity(animeList)) - return ctx.HTML(components.Airing(animeList)) } diff --git a/pages/anime/anime.go b/pages/anime/anime.go index 96fc510d..0c65cd6f 100644 --- a/pages/anime/anime.go +++ b/pages/anime/anime.go @@ -12,7 +12,7 @@ func Get(ctx *aero.Context) string { anime, err := arn.GetAnime(id) if err != nil { - return ctx.Error(404, "Anime not found") + return ctx.Error(404, "Anime not found", err) } return ctx.HTML(components.Anime(anime)) diff --git a/pages/dashboard/dashboard.go b/pages/dashboard/dashboard.go index 479f3b51..9b5b2bcb 100644 --- a/pages/dashboard/dashboard.go +++ b/pages/dashboard/dashboard.go @@ -15,7 +15,7 @@ func Get(ctx *aero.Context) string { posts, err := arn.GetPosts() if err != nil { - return ctx.Error(500, "Error fetching posts") + return ctx.Error(500, "Error fetching posts", err) } sort.Sort(sort.Reverse(posts)) diff --git a/pages/posts/posts.go b/pages/posts/posts.go index 0195e644..28b88db4 100644 --- a/pages/posts/posts.go +++ b/pages/posts/posts.go @@ -12,7 +12,7 @@ func Get(ctx *aero.Context) string { post, err := arn.GetPost(id) if err != nil { - return ctx.Error(404, "Post not found") + return ctx.Error(404, "Post not found", err) } return ctx.HTML(components.Post(post)) diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 31cca56f..5d196cad 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -12,7 +12,7 @@ func Get(ctx *aero.Context) string { user, err := arn.GetUserByNick(nick) if err != nil { - return ctx.Error(404, "User not found") + return ctx.Error(404, "User not found", err) } return ctx.HTML(components.Profile(user, nil)) diff --git a/pages/threads/threads.go b/pages/threads/threads.go index f62eeb0e..39623e9c 100644 --- a/pages/threads/threads.go +++ b/pages/threads/threads.go @@ -14,7 +14,7 @@ func Get(ctx *aero.Context) string { thread, err := arn.GetThread(id) if err != nil { - return ctx.Error(404, "Thread not found") + return ctx.Error(404, "Thread not found", err) } replies, filterErr := arn.FilterPosts(func(post *arn.Post) bool { @@ -24,7 +24,7 @@ func Get(ctx *aero.Context) string { sort.Sort(replies) if filterErr != nil { - return ctx.Error(500, "Error fetching thread replies") + return ctx.Error(500, "Error fetching thread replies", err) } return ctx.HTML(components.Thread(thread, replies))