FlowiseAI/Flowise · error · InternalFlowiseError

Error: chatMessagesController.removeAllChatMessages - organi

Error message

Error: chatMessagesController.removeAllChatMessages - organization ${orgId} not found!

What it means

Thrown by removeAllChatMessages with HTTP 404 after the id guard passes, when orgId = req.user?.activeOrganizationId is falsy. The interpolated message reads 'organization undefined not found'. The handler then also requires a workspace (a third guard), so satisfying the org check is necessary but not sufficient. The organization id is provided by the auth/session middleware; its absence means the caller has no active org context.

Source

Thrown at packages/server/src/controllers/chat-messages/index.ts:156

        )
        return res.json(parseAPIResponse(apiResponse))
    } catch (error) {
        next(error)
    }
}

const removeAllChatMessages = async (req: Request, res: Response, next: NextFunction) => {
    try {
        const appServer = getRunningExpressApp()
        if (typeof req.params === 'undefined' || !req.params.id) {
            throw new InternalFlowiseError(
                StatusCodes.PRECONDITION_FAILED,
                'Error: chatMessagesController.removeAllChatMessages - id not provided!'
            )
        }
        const orgId = req.user?.activeOrganizationId
        if (!orgId) {
            throw new InternalFlowiseError(
                StatusCodes.NOT_FOUND,
                `Error: chatMessagesController.removeAllChatMessages - organization ${orgId} not found!`
            )
        }
        const workspaceId = req.user?.activeWorkspaceId
        if (!workspaceId) {
            throw new InternalFlowiseError(
                StatusCodes.NOT_FOUND,
                `Error: chatMessagesController.removeAllChatMessages - workspace ${workspaceId} not found!`
            )
        }
        const chatflowid = req.params.id
        const chatflow = await chatflowsService.getChatflowByIdForWorkspace(req.params.id, workspaceId)
        if (!chatflow) {
            return res.status(404).send('Chatflow not found')
        }
        const flowData = chatflow.flowData
        const parsedFlowData: IReactFlowObject = JSON.parse(flowData)

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Ensure the user belongs to an organization and the session/JWT carries activeOrganizationId before clearing messages.
  2. Have the client switch into an org, then retry.
  3. Verify auth middleware populates activeOrganizationId; note a workspace will also be required next.
Defensive patterns

Strategy: try-catch

Type guard

const hasActiveOrg = (u: unknown): u is { activeOrganizationId: string } =>
  !!u && typeof u === 'object' &&
  typeof (u as any).activeOrganizationId === 'string' &&
  (u as any).activeOrganizationId.length > 0

Try / catch

try {
  await removeAllChatMessages(id)
} catch (err) {
  if (err?.statusCode === 404 && /organization .* not found/i.test(err.message)) {
    await selectOrganization()
    return removeAllChatMessages(id)
  }
  throw err
}

Prevention

When it happens

Trigger: Authenticated DELETE /api/v1/chatmessage/<id> from a session whose JWT has no activeOrganizationId — user not in any org, or org claim never set.

Common situations: User provisioned without an org; SSO/JIT that omits org assignment; token minted without the org claim; non-enterprise deployment where this enterprise-guarded delete route is reached anyway.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/11c1245db851e4b1. Report an issue: GitHub.