notify me on http errors

This commit is contained in:
Michael Zhang 2020-10-17 18:05:12 -05:00
parent 540505e4bd
commit 8c734dd6f2
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
2 changed files with 9 additions and 4 deletions

View file

@ -53,6 +53,12 @@ func NewBot(config *config.Config, db *db.Db, api *osuapi.Osuapi) (bot *Bot, err
return
}
func (bot *Bot) NotifyError(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
channel, _ := bot.UserChannelCreate("100443064228646912")
bot.ChannelMessageSend(channel.ID, msg)
}
func (bot *Bot) errWrap(fn interface{}) interface{} {
val := reflect.ValueOf(fn)
origType := reflect.TypeOf(fn)
@ -66,10 +72,7 @@ func (bot *Bot) errWrap(fn interface{}) interface{} {
if len(res) > 0 && !res[0].IsNil() {
err := res[0].Interface().(error)
if err != nil {
msg := fmt.Sprintf("error: %s", err)
channel, _ := bot.UserChannelCreate("100443064228646912")
id, _ := bot.ChannelMessageSend(channel.ID, msg)
log.Println(id, msg)
bot.NotifyError("error: %s", err)
}
}
return []reflect.Value{}

View file

@ -20,6 +20,8 @@ func (s *Scraper) scrapePendingMaps() {
pendingSets, err := s.api.SearchBeatmaps("pending")
if err != nil {
log.Println("error fetching pending sets", err)
s.bot.NotifyError("failed to fetch pending sets", err)
return
}
allNewMaps := make(map[int][]osuapi.Beatmapset, 0)