{"record":{"id":"f72df7df3d2b8b81","repo":"hcengineering/platform","slug":"already-processing-request","errorCode":null,"errorMessage":"Already processing request","messagePattern":"Already processing request","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"plugins/telegram-resources/src/components/Connect.svelte","lineNumber":47,"sourceCode":"  export let reconnect: boolean = false\n\n  let phone: string = ''\n  let code: string = ''\n  let password: string = ''\n  let error: string = ''\n  let isLoading: boolean = false\n\n  const dispatch = createEventDispatcher()\n\n  function close (value?: string): void {\n    const connected = state.mode === 'Authorized' || state.mode === 'Configured'\n    dispatch('close', { value, connected })\n  }\n\n  // Wrapper for command API with loading state management\n  async function commandWithLoading (phone: string, action: 'start' | 'next', data?: string): Promise<IntegrationState> {\n    if (isLoading) {\n      throw new Error('Already processing request')\n    }\n\n    try {\n      isLoading = true\n      return await command(phone, action, data)\n    } finally {\n      isLoading = false\n    }\n  }\n\n  interface UIState {\n    mode: 'Loading' | 'WantPhone' | 'WantCode' | 'WantPassword' | 'Authorized' | 'Configured' | 'Unauthorized' | 'Error'\n    hint?: string\n    errorLabel?: IntlString\n\n    buttons?: {\n      primary?: { label: IntlString, handler?: () => any, disabled?: boolean }\n      secondary?: { label: IntlString, handler?: () => any }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/telegram-resources/src/components/Connect.svelte#L29-L65","documentation":"Connect.svelte wraps telegram command API calls (start/next code submission) in commandWithLoading, which guards a component-level `isLoading` flag. If a new command is issued while a previous one is still in flight, it throws 'Already processing request' to prevent interleaving telegram login steps (phone → code) out of order.","triggerScenarios":"Calling commandWithLoading(phone, 'start'|'next', data) while `isLoading` is true — e.g. double-clicking the confirm button or submitting the next auth step before the previous command resolves.","commonSituations":"Impatient user clicking the code-submit button twice on a slow telegram integration server; Enter key submitting twice; a hung previous request (network stall) keeping isLoading true indefinitely.","solutions":["Disable the submit button and show a spinner while isLoading to prevent duplicate invocations.","Debounce or deduplicate the command call in the click/submit handler.","Add a timeout/abort for in-flight command() calls so isLoading cannot stay stuck on a hung request.","Catch the error in the caller and surface a friendly 'please wait' message instead of a stack trace."],"exampleFix":"// before\nasync function submit () {\n  await commandWithLoading(phone, 'next', code)\n}\n// after\nasync function submit () {\n  if (isLoading) return\n  try {\n    await commandWithLoading(phone, 'next', code)\n  } catch (e) {\n    if (e.message === 'Already processing request') return\n    throw e\n  }\n}","handlingStrategy":"validation","validationCode":"if (isLoading) return // already in flight\nawait commandWithLoading(phone, 'next', code)","typeGuard":null,"tryCatchPattern":"try {\n  await commandWithLoading(phone, 'next', code)\n} catch (e) {\n  if (e.message === 'Already processing request') {\n    showNotification('Please wait for the current step to finish')\n  } else throw e\n}","preventionTips":["Disable submit buttons while isLoading","Debounce click/submit handlers","Add timeouts/aborts so isLoading cannot get stuck"],"tags":["concurrency","ui","telegram","reentrancy"],"backgroundTag":"operation-already-in-progress","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}