Improved error logging

This commit is contained in:
2018-07-07 12:42:00 +09:00
parent bf544836fa
commit e46c9b1586
41 changed files with 69 additions and 65 deletions
middleware
pages
admin
anime
animeimport
animelist
charge
dashboard
editlog
editor
filteranime
filtersoundtracks
jobs
embed
episode
explore/explorerelations
inventory
listimport
listimport.go
listimportanilist
listimportkitsu
listimportmyanimelist
newthread
notifications
paypal
post/editpost
settings
shop
thread/editthread
upload
user

@ -57,24 +57,28 @@ func logRequest(ctx *aero.Context, responseTime time.Duration) {
}
// Log every request
id := "[id]"
nick := "[guest]"
if user != nil {
request.Info(user.Nick, ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI())
} else {
request.Info("[guest]", ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI())
id = user.ID
nick = user.Nick
}
request.Info(nick, id, ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI())
// Log all requests that failed
switch ctx.StatusCode {
case http.StatusOK, http.StatusFound, http.StatusMovedPermanently, http.StatusPermanentRedirect, http.StatusTemporaryRedirect:
// Ok.
default:
err.Error(http.StatusText(ctx.StatusCode), ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI())
err.Error(nick, id, ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI(), ctx.ErrorMessage)
}
// Notify us about long requests.
// However ignore requests under /auth/ because those depend on 3rd party servers.
if responseTime >= 300*time.Millisecond && !strings.HasPrefix(ctx.URI(), "/auth/") && !strings.HasPrefix(ctx.URI(), "/sitemap/") {
err.Error("Long response time", ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI())
err.Error("Long response time", nick, id, ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI())
}
}

@ -15,11 +15,11 @@ func PurchaseHistory(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
if user.Role != "admin" {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
purchases, err := arn.AllPurchases()

@ -16,11 +16,11 @@ func UserRegistrations(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
if user.Role != "admin" {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
total := 0

@ -16,7 +16,7 @@ func Main(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime")
}
anime, err := arn.GetAnime(id)
@ -34,7 +34,7 @@ func Images(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime")
}
anime, err := arn.GetAnime(id)
@ -52,7 +52,7 @@ func Characters(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit")
}
anime, err := arn.GetAnime(id)
@ -76,7 +76,7 @@ func Relations(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit")
}
anime, err := arn.GetAnime(id)
@ -100,7 +100,7 @@ func Episodes(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit")
}
anime, err := arn.GetAnime(id)

@ -16,7 +16,7 @@ func RedirectByMapping(mappingName string) func(*aero.Context) string {
anime := finder.GetAnime(id)
if anime == nil {
return ctx.Error(http.StatusNotFound, "Anime not found", nil)
return ctx.Error(http.StatusNotFound, "Anime not found")
}
return utils.SmartRedirect(ctx, "/anime/"+anime.ID)

@ -17,7 +17,7 @@ func DeleteKitsu(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
// Check that the anime really exists

@ -19,7 +19,7 @@ func Kitsu(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
kitsuAnimeObj, err := arn.Kitsu.Get("Anime", id)

@ -38,7 +38,7 @@ func AnimeList(ctx *aero.Context, user *arn.User, status string) string {
animeList := viewUser.AnimeList()
if animeList == nil {
return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
return ctx.Error(http.StatusNotFound, "Anime list not found")
}
statusList := animeList.FilterStatus(status)

@ -12,7 +12,7 @@ func Redirect(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
return ctx.Redirect("/+" + user.Nick + ctx.URI())

@ -14,7 +14,7 @@ func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
return ctx.HTML(components.Charge(user))

@ -26,7 +26,7 @@ package dashboard
// user := utils.GetUser(ctx)
// if user == nil {
// return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
// return ctx.Error(http.StatusUnauthorized, "Not logged in")
// }
// flow.Parallel(func() {

@ -24,7 +24,7 @@ func Get(ctx *aero.Context) string {
nick := ctx.Get("nick")
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
viewUser, err := arn.GetUserByNick(nick)

@ -17,7 +17,7 @@ func editorList(ctx *aero.Context, title string, filter func(*arn.Anime) bool, s
user := utils.GetUser(ctx)
if user == nil || (user.Role != "admin" && user.Role != "editor") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
animes, count := filterAnime(ctx, user, filter)

@ -17,7 +17,7 @@ func editorList(ctx *aero.Context, title string, filter func(*arn.SoundTrack) bo
user := utils.GetUser(ctx)
if user == nil || (user.Role != "admin" && user.Role != "editor") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
tracks, count := filterSoundTracks(ctx, user, filter)

@ -21,18 +21,18 @@ func Start(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
jobName := ctx.Get("job")
job := jobInfo[jobName]
if job == nil {
return ctx.Error(http.StatusBadRequest, "Job not available", nil)
return ctx.Error(http.StatusBadRequest, "Job not available")
}
if job.IsRunning() {
return ctx.Error(http.StatusBadRequest, "Job is currently running!", nil)
return ctx.Error(http.StatusBadRequest, "Job is currently running!")
}
job.Start()

@ -25,7 +25,7 @@ func Get(ctx *aero.Context) string {
animeList := user.AnimeList()
if animeList == nil {
return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
return ctx.Error(http.StatusNotFound, "Anime list not found")
}
watchingList := animeList.Watching()

@ -36,7 +36,7 @@ func Get(ctx *aero.Context) string {
episode := animeEpisodes.Find(episodeNumber)
if episode == nil {
return ctx.Error(http.StatusNotFound, "Anime episode not found", nil)
return ctx.Error(http.StatusNotFound, "Anime episode not found")
}
return ctx.HTML(components.AnimeEpisode(anime, episode, user))

@ -16,7 +16,7 @@ func Sequels(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
animeList := user.AnimeList()

@ -17,7 +17,7 @@ func Get(ctx *aero.Context) string {
viewUser := user
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
inventory, err := arn.GetInventory(viewUser.ID)

@ -13,7 +13,7 @@ func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
return ctx.HTML(components.ImportLists(user))

@ -16,7 +16,7 @@ func Preview(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
@ -33,7 +33,7 @@ func Finish(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
@ -76,7 +76,7 @@ func getMatches(ctx *aero.Context) ([]*arn.AniListMatch, string) {
user := utils.GetUser(ctx)
if user == nil {
return nil, ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return nil, ctx.Error(http.StatusBadRequest, "Not logged in")
}
// Get user

@ -15,7 +15,7 @@ func Preview(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
@ -32,7 +32,7 @@ func Finish(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
@ -87,7 +87,7 @@ func getMatches(ctx *aero.Context) ([]*arn.KitsuMatch, string) {
user := utils.GetUser(ctx)
if user == nil {
return nil, ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return nil, ctx.Error(http.StatusBadRequest, "Not logged in")
}
kitsuUser, err := kitsu.GetUser(user.Accounts.Kitsu.Nick)

@ -16,7 +16,7 @@ func Preview(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
@ -33,7 +33,7 @@ func Finish(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
matches, response := getMatches(ctx)
@ -83,7 +83,7 @@ func getMatches(ctx *aero.Context) ([]*arn.MyAnimeListMatch, string) {
user := utils.GetUser(ctx)
if user == nil {
return nil, ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return nil, ctx.Error(http.StatusBadRequest, "Not logged in")
}
malAnimeList, err := mal.GetAnimeList(user.Accounts.MyAnimeList.Nick)

@ -13,7 +13,7 @@ func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
return ctx.HTML(components.NewThread(user))

@ -14,7 +14,7 @@ func CountUnseen(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
unseen := user.Notifications().CountUnseen()
@ -27,7 +27,7 @@ func MarkNotificationsAsSeen(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
notifications := user.Notifications().Notifications()
@ -45,7 +45,7 @@ func Test(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
user.SendNotification(&arn.PushNotification{

@ -18,7 +18,7 @@ func ByUser(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
var viewUser *arn.User

@ -15,7 +15,7 @@ func CreatePayment(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
// Verify amount
@ -29,7 +29,7 @@ func CreatePayment(ctx *aero.Context) string {
case "1000", "2000", "3000", "6000", "12000", "25000", "50000", "75000":
// OK
default:
return ctx.Error(http.StatusBadRequest, "Incorrect amount", nil)
return ctx.Error(http.StatusBadRequest, "Incorrect amount")
}
// Initiate PayPal client

@ -20,7 +20,7 @@ func Success(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
paymentID := ctx.Query("paymentId")

@ -16,7 +16,7 @@ func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this post", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this post")
}
post, err := arn.GetPost(id)

@ -14,7 +14,7 @@ func Get(component func(*arn.User) string) func(*aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
return ctx.HTML(component(user))

@ -21,7 +21,7 @@ func BuyItem(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
// Item ID and quantity
@ -42,7 +42,7 @@ func BuyItem(ctx *aero.Context) string {
totalPrice := int(item.Price) * quantity
if user.Balance < totalPrice {
return ctx.Error(http.StatusBadRequest, "Not enough gems. You need to charge up your balance before you can buy this item.", nil)
return ctx.Error(http.StatusBadRequest, "Not enough gems. You need to charge up your balance before you can buy this item.")
}
user.Balance -= totalPrice

@ -15,7 +15,7 @@ func PurchaseHistory(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
purchases, err := arn.FilterPurchases(func(purchase *arn.Purchase) bool {

@ -16,7 +16,7 @@ func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
items, err := arn.AllShopItems()

@ -16,7 +16,7 @@ func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this thread", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this thread")
}
thread, err := arn.GetThread(id)

@ -15,7 +15,7 @@ func AMVFile(ctx *aero.Context) string {
amvID := ctx.Get("id")
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
amv, err := arn.GetAMV(amvID)

@ -15,7 +15,7 @@ func AnimeImage(ctx *aero.Context) string {
animeID := ctx.Get("id")
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
anime, err := arn.GetAnime(animeID)

@ -12,7 +12,7 @@ func Avatar(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
// Retrieve file from post body

@ -15,7 +15,7 @@ func CharacterImage(ctx *aero.Context) string {
characterID := ctx.Get("id")
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
character, err := arn.GetCharacter(characterID)

@ -12,11 +12,11 @@ func Cover(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
if !user.IsPro() {
return ctx.Error(http.StatusUnauthorized, "Only available for PRO users", nil)
return ctx.Error(http.StatusUnauthorized, "Only available for PRO users")
}
// Retrieve file from post body

@ -15,7 +15,7 @@ func Edit(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil || user.Role != "admin" {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this user", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this user")
}
viewUser, err := arn.GetUserByNick(nick)

@ -13,11 +13,11 @@ func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
return ctx.Error(http.StatusBadRequest, "Not logged in")
}
if user.Nick == "" {
return ctx.Error(http.StatusInternalServerError, "User did not set a nickname", nil)
return ctx.Error(http.StatusInternalServerError, "User did not set a nickname")
}
return profile.Profile(ctx, user)