Skip to content

Commit 8e36fe0

Browse files
committed
refactor: update ExtractorAuth method to return error instead of boolean
Signed-off-by: tbxark <[email protected]>
1 parent 876a5c0 commit 8e36fe0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

telegram/bot.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,30 @@ func (b *Bot) Close(ctx context.Context) error {
4848
return err
4949
}
5050

51-
func (b *Bot) ExtractorAuth(ctx context.Context, tBot *bot.Bot, update *Update) (context.Context, bool) {
51+
func (b *Bot) ExtractorAuth(ctx context.Context, tBot *bot.Bot, update *Update) (context.Context, error) {
5252
if b.AuthExtractor != nil {
5353
info, err := b.AuthExtractor(ctx, update)
5454
if err != nil {
5555
if b.ErrorHandler != nil {
5656
b.ErrorHandler(ctx, tBot, update, err)
5757
}
58-
return nil, true
58+
return nil, err
5959
}
6060
c := NewContext(ctx)
6161
for k, v := range info {
6262
c.SetValue(k, v)
6363
}
64-
return c, false
64+
return c, nil
6565
}
66-
return ctx, false
66+
return ctx, nil
6767
}
6868

6969
func (b *Bot) BindCommand(command string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc) {
7070
fn := WithMiddleware(handlerFunc, b.ErrorHandler, middlewares...)
7171
command = "/" + strings.TrimPrefix(command, "/")
7272
b.bot.RegisterHandler(bot.HandlerTypeMessageText, command, bot.MatchTypePrefix, func(ctx context.Context, tBot *bot.Bot, update *models.Update) {
73-
ctx, done := b.ExtractorAuth(ctx, tBot, (*Update)(update))
74-
if done {
73+
ctx, err := b.ExtractorAuth(ctx, tBot, (*Update)(update))
74+
if err != nil {
7575
return
7676
}
7777
fn(ctx, tBot, update)
@@ -81,8 +81,8 @@ func (b *Bot) BindCommand(command string, handlerFunc HandlerFunc, middlewares .
8181
func (b *Bot) BindCallback(route string, handlerFunc HandlerFunc, middlewares ...MiddlewareFunc) {
8282
fn := WithMiddleware(handlerFunc, b.ErrorHandler, middlewares...)
8383
b.bot.RegisterHandler(bot.HandlerTypeCallbackQueryData, route+":", bot.MatchTypePrefix, func(ctx context.Context, tBot *bot.Bot, update *models.Update) {
84-
ctx, done := b.ExtractorAuth(ctx, tBot, (*Update)(update))
85-
if done {
84+
ctx, err := b.ExtractorAuth(ctx, tBot, (*Update)(update))
85+
if err != nil {
8686
return
8787
}
8888
fn(ctx, tBot, update)

0 commit comments

Comments
 (0)