{"record":{"id":"efb1aabfd01734ff","repo":"windmill-labs/windmill","slug":"preview-failed-response-status-response-st","errorCode":null,"errorMessage":"Preview failed: ${response.status} - ${response.statusText} - ${await response.text()}","messagePattern":"Preview failed: (.+?) - (.+?) - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/script/script.ts","lineNumber":2053,"sourceCode":"      workspace.remote +\n      \"api/w/\" +\n      workspace.workspaceId +\n      \"/jobs/run/preview_bundle\";\n\n    const extraHeaders = getHeaders();\n    const response = await fetch(url, {\n      method: \"POST\",\n      headers: {\n        Authorization: `Bearer ${workspace.token}`,\n        ...extraHeaders,\n      },\n      body: form,\n    });\n\n    await detectAuthGatewayChallenge(response, url);\n\n    if (!response.ok) {\n      throw new Error(\n        `Preview failed: ${response.status} - ${response.statusText} - ${await response.text()}`\n      );\n    }\n\n    const jobId = await response.text();\n    if (!opts.silent) {\n      await track_job(workspace.workspaceId, jobId);\n    }\n\n    // Wait for the job to complete and get the result\n    while (true) {\n      try {\n        const completedJob = await wmill.getCompletedJob({\n          workspace: workspace.workspaceId,\n          id: jobId,\n        });\n\n        const result = completedJob.result ?? {};","sourceCodeStart":2035,"sourceCodeEnd":2071,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/script/script.ts#L2035-L2071","documentation":"The preview command POSTs a form to the instance's preview/app endpoint. If the HTTP response is not ok, the CLI throws 'Preview failed' embedding the status code, status text, and response body via `detectAuthGatewayChallenge` having already checked for auth-gateway interception. This surfaces server-side validation or auth failures from the raw HTTP layer.","triggerScenarios":"Previewing a script whose code fails server-side validation (400), hitting an endpoint that requires auth while the token is expired (401/403), the path/endpoint not existing on the target instance (404), or a reverse proxy returning 502/503.","commonSituations":"Expired or mis-scoped API token; pointing the CLI at the wrong instance URL (`--base-url`/workspace config) behind a proxy; previewing code with syntax errors the server rejects; corporate SSO/gateway challenging the request.","solutions":["Read the status and body in the message: 401/403 → re-login with `wmill login` or refresh the token.","400 → fix the script error reported in the response body.","Verify the instance URL and workspace with `wmill workspace show`.","If behind a gateway/proxy, check its logs; 502/503 means the instance or upstream is down."],"exampleFix":"// before\nwmill script preview f/my_script.py   # 401 from expired token\n// after\nwmill login\nwmill script preview f/my_script.py","handlingStrategy":"try-catch","validationCode":"const cfg = JSON.parse(readFileSync(configPath, 'utf8'));\nconst res = await fetch(cfg.baseUrl + '/api/version');\nif (!res.ok) console.error('Instance unreachable or auth issue before preview');","typeGuard":null,"tryCatchPattern":"try {\n  await wmill.script.preview(file, opts);\n} catch (e) {\n  const m = String(e.message).match(/Preview failed: (\\d+)/);\n  if (m) {\n    const status = Number(m[1]);\n    if (status === 401 || status === 403) console.error('Re-authenticate: wmill login');\n    else if (status >= 500) console.error('Server-side issue; check instance/proxy health.');\n  }\n  throw e;\n}","preventionTips":["Refresh credentials (`wmill login`) before long CI sessions.","Validate script syntax locally (lint/format) before previewing.","Confirm `--base-url`/workspace points at the intended instance, especially behind proxies."],"tags":["cli","http","preview","network"],"backgroundTag":"http-request-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}