Improved logging in avatar code

This commit is contained in:
2017-06-15 16:56:06 +02:00
parent c858a58123
commit bccee5968b
4 changed files with 25 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"net/http"
"regexp"
"time"
@ -21,6 +22,7 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
// If the user has no username we can't get an avatar.
if malNick == "" {
avatarLog.Error("MAL", user.Nick, "No MAL nick")
return nil
}
@ -28,7 +30,13 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
userInfoURL := "https://myanimelist.net/malappinfo.php?u=" + malNick
response, xml, networkErr := gorequest.New().Get(userInfoURL).End()
if networkErr != nil || response.StatusCode != 200 {
if networkErr != nil {
avatarLog.Error("MAL", user.Nick, userInfoURL, networkErr)
return nil
}
if response.StatusCode != http.StatusOK {
avatarLog.Error("MAL", user.Nick, userInfoURL, response.StatusCode)
return nil
}
@ -36,6 +44,7 @@ func (source *MyAnimeList) GetAvatar(user *arn.User) *Avatar {
matches := userIDRegex.FindStringSubmatch(xml)
if matches == nil || len(matches) < 2 {
avatarLog.Error("MAL", user.Nick, "Could not find user ID")
return nil
}