Mintplex-Labs/anything-llm · warning

Bad Request

Error message

Bad Request

What it means

Returned by POST /workspace/:slug/update when the workspace slug lookup returns null. In single-user mode Workspace.get({slug}) is null; in multi-user mode Workspace.getWithUser(user,{slug}) is null when the user lacks access. The endpoint returns 400 (not 404) to signal the slug did not resolve.

Source

Thrown at server/endpoints/workspaces.js:93

        response.sendStatus(500).end();
      }
    }
  );

  app.post(
    "/workspace/:slug/update",
    [validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
    async (request, response) => {
      try {
        const user = await userFromSession(request, response);
        const { slug = null } = request.params;
        const data = reqBody(request);
        const currWorkspace = multiUserMode(response)
          ? await Workspace.getWithUser(user, { slug })
          : await Workspace.get({ slug });

        if (!currWorkspace) {
          response.sendStatus(400).end();
          return;
        }

        await Workspace.trackChange(currWorkspace, data, user);
        const { workspace, message } = await Workspace.update(
          currWorkspace.id,
          data
        );
        response.status(200).json({ workspace, message });
      } catch (e) {
        console.error(e.message, e);
        response.sendStatus(500).end();
      }
    }
  );

  app.post(
    "/workspace/:slug/upload",

View on GitHub (pinned to 526360e320)

Solutions

  1. Call GET /workspace/:slug to verify the slug resolves before issuing the update.
  2. In multi-user mode, confirm the caller is an admin or manager with access to the workspace.
  3. Ensure the URL uses the current, exact workspace slug.
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the workspace slug resolves before updating:
async function workspaceExists(api, slug) {
  const res = await api.get(`/workspace/${encodeURIComponent(slug)}`);
  return res.status === 200 && !!res.data?.workspace;
}

if (!(await workspaceExists(api, slug))) {
  throw new Error(`Workspace '${slug}' not found`);
}

Type guard

function isValidWorkspaceSlug(slug) {
  return typeof slug === 'string' && slug.trim().length > 0;
}

Try / catch

try {
  const res = await api.post(`/workspace/${slug}/update`, data);
} catch (e) {
  if (e.response?.status === 400) {
    // workspace not found — refresh workspace list and retry
  } else { throw e; }
}

Prevention

When it happens

Trigger: The :slug URL parameter is misspelled, belongs to a deleted workspace, or in multi-user mode the caller lacks membership.

Common situations: Frontend holds a stale slug after the workspace was renamed or deleted; permissions changed and the user lost access.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/8a955cfe9e5a9657. Report an issue: GitHub.