{"record":{"id":"785648649d3924d7","repo":"hcengineering/platform","slug":"phone-code-invalid","errorCode":"PHONE_CODE_INVALID","errorMessage":"err.message","messagePattern":"err\\.message","errorType":"error_code","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"services/telegram/pod-telegram/src/telegram.ts","lineNumber":70,"sourceCode":"        })\n      )\n\n      if (res instanceof Api.auth.AuthorizationSignUpRequired) {\n        throw Error('Account does not exist')\n      }\n\n      this.finish()\n      return true\n    } catch (err: unknown) {\n      if (err instanceof RPCError) {\n        const untypedErr: any = err\n        if (untypedErr.errorMessage === 'SESSION_PASSWORD_NEEDED') {\n          this._state = 'pass'\n          return false\n        }\n\n        if (untypedErr.errorMessage === 'PHONE_CODE_INVALID') {\n          throw new ApiError(Code.PhoneCodeInvalid, err.message)\n        }\n      }\n\n      throw err\n    }\n  }\n\n  async pass (password: string): Promise<void> {\n    if (this._state !== 'pass') {\n      throw Error('Invalid sign in method')\n    }\n\n    const passSrpRes = await this.client.invoke(new Api.account.GetPassword())\n    const passSrpCheck = await computeCheck(passSrpRes, password)\n    await this.client.invoke(new Api.auth.CheckPassword({ password: passSrpCheck }))\n\n    this.finish()\n  }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/telegram/pod-telegram/src/telegram.ts#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nclient.submitCode(userInput)\n// after\ntry {\n  await client.submitCode(userInput)\n} catch (err) {\n  if (err.code === Code.PhoneCodeInvalid) {\n    showNotification('The code is invalid or expired. Request a new one and try again.')\n  } else throw err\n}","handlingStrategy":"try-catch","validationCode":"// No pre-call check exists for Telegram code validity; validate input format client-side:\nif (!/^\\d{5,6}$/.test(userCode.trim())) {\n  showInputError('Enter the 5–6 digit code from your Telegram app.')\n}","typeGuard":"function isPhoneCodeInvalid(err: unknown): boolean {\n  return err instanceof ApiError && (err as ApiError).code === Code.PhoneCodeInvalid\n}","tryCatchPattern":"try {\n  await telegramClient.code(phoneCode)\n} catch (err) {\n  if (err instanceof ApiError && err.code === Code.PhoneCodeInvalid) {\n    showNotification('Invalid or expired code. Request a new one and try again.')\n  } else throw err\n}","preventionTips":["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."],"tags":["telegram","authentication","invalid-code","gramjs"],"backgroundTag":"phone-code-invalid","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}