hcengineering/platform · error · ApiError
PHONE_CODE_INVALID
PHONE_CODE_INVALID
Error message
err.message
What it means
In pod-telegram's code() method, a PHONE_CODE_INVALID error from the Telegram (GramJS) client is rethrown as ApiError(Code.PhoneCodeInvalid, err.message). Telegram rejected the login code entered by the user — the code does not match the one sent to the user's Telegram account.
Source
Thrown at services/telegram/pod-telegram/src/telegram.ts:70
})
)
if (res instanceof Api.auth.AuthorizationSignUpRequired) {
throw Error('Account does not exist')
}
this.finish()
return true
} catch (err: unknown) {
if (err instanceof RPCError) {
const untypedErr: any = err
if (untypedErr.errorMessage === 'SESSION_PASSWORD_NEEDED') {
this._state = 'pass'
return false
}
if (untypedErr.errorMessage === 'PHONE_CODE_INVALID') {
throw new ApiError(Code.PhoneCodeInvalid, err.message)
}
}
throw err
}
}
async pass (password: string): Promise<void> {
if (this._state !== 'pass') {
throw Error('Invalid sign in method')
}
const passSrpRes = await this.client.invoke(new Api.account.GetPassword())
const passSrpCheck = await computeCheck(passSrpRes, password)
await this.client.invoke(new Api.auth.CheckPassword({ password: passSrpCheck }))
this.finish()
}View on GitHub (pinned to 63e28dc964)
Solutions
- Ask the user to re-enter the code carefully from the latest Telegram message.
- Request a fresh code (resend) and submit it promptly before it expires.
- Ensure the UI clears stale code state so an old code cannot be resubmitted.
- Surface Code.PhoneCodeInvalid to the user as a clear 'invalid code, try again' message instead of a generic error.
Example fix
// before
client.submitCode(userInput)
// after
try {
await client.submitCode(userInput)
} catch (err) {
if (err.code === Code.PhoneCodeInvalid) {
showNotification('The code is invalid or expired. Request a new one and try again.')
} else throw err
} Defensive patterns
Strategy: try-catch
Validate before calling
// No pre-call check exists for Telegram code validity; validate input format client-side:
if (!/^\d{5,6}$/.test(userCode.trim())) {
showInputError('Enter the 5–6 digit code from your Telegram app.')
} Type guard
function isPhoneCodeInvalid(err: unknown): boolean {
return err instanceof ApiError && (err as ApiError).code === Code.PhoneCodeInvalid
} Try / catch
try {
await telegramClient.code(phoneCode)
} catch (err) {
if (err instanceof ApiError && err.code === Code.PhoneCodeInvalid) {
showNotification('Invalid or expired code. Request a new one and try again.')
} else throw err
} Prevention
- Submit the code promptly — Telegram codes expire within minutes.
- Always use the most recent code; requesting a new one invalidates the old.
- Add client-side format validation before submission.
- Map Code.PhoneCodeInvalid to a clear user-facing message.
When it happens
Trigger: User types a wrong code in the Telegram login form; the code expires before submission; a code from a different session/phone is entered; the code is reused after already being consumed by another sign-in attempt.
Common situations: Users mistyping the SMS/Telegram-app code, waiting too long between requesting and entering the code, or requesting a new code and submitting the old one.
Related errors
- Workspace ${options.workspace} not found
- await response.text()
- Login failed
- Workspace not found
- Workspace or account not found in token
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/785648649d3924d7.
Report an issue: GitHub.