{"record":{"id":"dbd410314d7ca028","repo":"different-ai/openwork","slug":"failed-to-update-auto-import-response-status","errorCode":null,"errorMessage":"Failed to update auto-import (${response.status}).","messagePattern":"Failed to update auto-import \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx","lineNumber":1003,"sourceCode":"\nexport function useSetConnectorInstanceAutoImport() {\n  const queryClient = useQueryClient();\n  const { runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (input: { autoImportNewPlugins: boolean; connectorInstanceId: string }) => {\n      await runReauthableAction(\"set-connector-auto-import\", async () => {\n      const { response, payload } = await requestJson(\n        `/v1/connector-instances/${encodeURIComponent(input.connectorInstanceId)}/auto-import`,\n        {\n          method: \"POST\",\n          body: JSON.stringify({ autoImportNewPlugins: input.autoImportNewPlugins }),\n        },\n        15000,\n      );\n\n      if (!response.ok) {\n        throw getRequestError(payload, response, `Failed to update auto-import (${response.status}).`);\n      }\n\n      });\n      return input.autoImportNewPlugins;\n    },\n    onSuccess: (_result, variables) => {\n      queryClient.invalidateQueries({\n        queryKey: integrationQueryKeys.connectorInstanceConfiguration(variables.connectorInstanceId),\n      });\n    },\n  });\n}\n\nexport function useSyncConnectorInstanceNow() {\n  const queryClient = useQueryClient();\n  const { runReauthableAction } = useOrgDashboard();\n\n  return useMutation({","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx#L985-L1021","documentation":"Thrown when toggling auto-import of new plugins for an integration fails with a non-2xx response. The mutation POSTs {autoImportNewPlugins} with a 15s timeout and throws getRequestError(payload, response, ...) on failure; the message is the server's error text or the fallback \"Failed to update auto-import (<status>).\", with 403 {error:'reauth'} upgraded to ReauthRequiredError.","triggerScenarios":"PUT/POST of the auto-import setting returns non-ok: 401/403 (expired session or insufficient role — often requires admin), 404 (connector instance was removed concurrently), 422 (value not a boolean or instance not in a state that supports auto-import), 5xx, or response later than the 15000ms timeout.","commonSituations":"Toggling the switch on an integration whose instance was deleted in another tab; non-admin member flipping an admin-only setting; flaky network at the 15s limit; server rejects auto-import for connectors without discovery support.","solutions":["Roll back the optimistic UI toggle to the prior value (variables.autoImportNewPlugins is available in onError) and surface the error.","On 404, refresh the integration list — the instance no longer exists.","On 403, confirm the user's role; only admins/owners can change org integration settings.","Retry once on 5xx/network timeout before showing a persistent error."],"exampleFix":"// before\nonError: (error) => { toast(error.message); }\n// after\nonError: (error, variables) => {\n  queryClient.setQueryData(integrationQueryKeys.list(orgSlug), (old) =>\n    rollbackAutoImport(old, variables.connectorInstanceId, !variables.autoImportNewPlugins));\n  toast(error.message);\n}","handlingStrategy":"try-catch","validationCode":"// before toggling\nif (typeof nextValue !== \"boolean\") throw new Error(\"autoImportNewPlugins must be a boolean.\");\nif (!hasOrgAdminRole(userRole)) throw new Error(\"Only admins can change auto-import.\");","typeGuard":"function isReauthError(e: unknown): e is ReauthRequiredError {\n  return e instanceof ReauthRequiredError;\n}","tryCatchPattern":"try {\n  await updateAutoImportMutation.mutateAsync({ connectorInstanceId, autoImportNewPlugins: next });\n} catch (error) {\n  queryClient.setQueryData(key, (old) => rollback(old, !next)); // undo optimistic toggle\n  if (isReauthError(error)) { startReauth(); return; }\n  showToast(error.message);\n}","preventionTips":["Only render the toggle for users with admin/owner role.","Always roll back the optimistic switch state in onError (variables are provided).","Invalidate the connector list after toggle so a concurrently deleted instance disappears.","Debounce rapid toggles to avoid racing requests."],"tags":["http","integrations","den-api","optimistic-ui"],"backgroundTag":"http-non-ok-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}