login: wrap some common errors to return 400 instead of 500 (#114)

This commit is contained in:
Brad Murray
2025-07-25 16:48:09 -04:00
committed by GitHub
parent 03fe8bf782
commit e7fe66a23e
4 changed files with 36 additions and 2 deletions
+7 -1
View File
@@ -91,7 +91,10 @@ func (c *Client) SendCode(ctx context.Context, phone string, options SendCodeOpt
// ErrPasswordAuthNeeded means that 2FA auth is required.
//
// Call Client.Password to provide 2FA password.
var ErrPasswordAuthNeeded = errors.New("2FA required")
var (
ErrPasswordAuthNeeded = errors.New("2FA required")
ErrPhoneCodeInvalid = errors.New("Phone code invalid")
)
// SignIn performs sign in with provided user phone, code and code hash.
//
@@ -108,6 +111,9 @@ func (c *Client) SignIn(ctx context.Context, phone, code, codeHash string) (*tg.
if tgerr.Is(err, "SESSION_PASSWORD_NEEDED") {
return nil, ErrPasswordAuthNeeded
}
if tgerr.Is(err, "PHONE_CODE_INVALID") {
return nil, ErrPasswordAuthNeeded
}
if err != nil {
return nil, errors.Wrap(err, "sign in")
}