{"record":{"id":"98b25733898bc9eb","repo":"FlowiseAI/Flowise","slug":"error-chatflowscontroller-togglescheduleenabled-98b257","errorCode":null,"errorMessage":"Error: chatflowsController.toggleScheduleEnabled - workspace not found!","messagePattern":"Error: chatflowsController\\.toggleScheduleEnabled - workspace not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/chatflows/index.ts","lineNumber":426,"sourceCode":"        }\n        const result = await scheduleService.deleteTriggerLogs(req.params.id, workspaceId, logIds as string[])\n        return res.json(result)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst toggleScheduleEnabled = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (!req.params?.id) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                'Error: chatflowsController.toggleScheduleEnabled - id not provided!'\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(StatusCodes.NOT_FOUND, 'Error: chatflowsController.toggleScheduleEnabled - workspace not found!')\n        }\n        const { enabled } = req.body\n        if (typeof enabled !== 'boolean') {\n            throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, '\"enabled\" must be a boolean')\n        }\n        const record = await scheduleService.toggleScheduleEnabled(req.params.id, workspaceId, enabled)\n        await ScheduleBeat.getInstance().onScheduleChanged(record.id, enabled ? 'upsert' : 'delete')\n        return res.json(record)\n    } catch (error) {\n        next(error)\n    }\n}\n\nexport default {\n    checkIfChatflowIsValidForStreaming,\n    checkIfChatflowIsValidForUploads,\n    deleteChatflow,\n    getAllChatflows,","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/chatflows/index.ts#L408-L444","documentation":"Thrown by toggleScheduleEnabled when req.user?.activeWorkspaceId is falsy. Enabling/disabling a schedule mutates workspace-scoped state and triggers ScheduleBeat, so the workspace context is mandatory. Returned as NOT_FOUND (404).","triggerScenarios":"Unauthenticated request, expired session, or user without an activeWorkspaceId reaching the toggle endpoint.","commonSituations":"Session lapsed while the schedule toggle was interactive, API key lacking workspace binding, or auth middleware skipped on the route.","solutions":["Authenticate and ensure the caller has an active workspace.","Handle 401/404 by re-authenticating before re-attempting the toggle.","Verify auth middleware ordering on the route."],"exampleFix":"// before\nfetch(url, { method: 'POST', body: JSON.stringify({ enabled: true }) })\n// after\nfetch(url, { method: 'POST', headers: { Authorization: `Bearer ${token}` }, body: JSON.stringify({ enabled: true }) })","handlingStrategy":"validation","validationCode":"async function authedFetch(url: string, init: RequestInit) {\n  if (!token) throw new Error('no auth token - cannot resolve active workspace')\n  return fetch(url, { ...init, headers: { ...init.headers, Authorization: `Bearer ${token}` } })\n}","typeGuard":"const hasActiveWorkspace = (u: unknown): u is { activeWorkspaceId: string } =>\n  !!u && typeof (u as any).activeWorkspaceId === 'string'","tryCatchPattern":"try { await api.toggleSchedule(id, enabled) } catch (e) { if (e.statusCode === 404 && /workspace/i.test(e.message)) { await reAuth(); await api.toggleSchedule(id, enabled) } else throw e }","preventionTips":["Authenticate schedule-toggle requests.","Ensure an active workspace is set.","Verify auth middleware on the route."],"tags":["flowise","controller","validation","workspace","auth","not-found","scheduling","typescript"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}