Improved error handling

This commit is contained in:
Eduard Urbach 2016-11-23 14:26:59 +09:00
parent da96ad60e7
commit 73b68c0a0f
7 changed files with 12 additions and 20 deletions

6
api.go
View File

@ -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)

View File

@ -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))
}

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))