[core] Fix: Allow start when no tokens are available

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-03-24 20:53:02 +01:00
parent 3213f4ac37
commit e8d39c19a4
Signed by: luzifer
GPG Key ID: D91C3E91E4CAD6F5
2 changed files with 9 additions and 1 deletions

View File

@ -38,6 +38,8 @@ type (
Service struct{ db database.Connector }
)
var ErrChannelNotAuthorized = errors.New("channel is not authorized")
func New(db database.Connector) (*Service, error) {
return &Service{db}, errors.Wrap(
db.DB().AutoMigrate(&extendedPermission{}),
@ -144,6 +146,9 @@ func (s Service) GetTwitchClientForChannel(channel string, cfg ClientConfig) (*t
)
if err = s.db.DB().First(&perm, "channel = ?", strings.TrimLeft(channel, "#")).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, ErrChannelNotAuthorized
}
return nil, errors.Wrap(err, "getting twitch credential from database")
}

View File

@ -272,7 +272,10 @@ func main() {
frontendReloadHooks.Ping()
},
}); err != nil {
log.WithError(err).Fatal("Unable to initialize Twitch client")
if !errors.Is(err, access.ErrChannelNotAuthorized) {
log.WithError(err).Fatal("Unable to initialize Twitch client")
}
twitchClient = twitch.New(cfg.TwitchClient, cfg.TwitchClientSecret, cfg.TwitchToken, "")
}
twitchWatch := newTwitchWatcher()