Improved error handling
This commit is contained in:
parent
da96ad60e7
commit
73b68c0a0f
6
api.go
6
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)
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user