{"record":{"id":"e43aa4cb650f497e","repo":"jackwener/OpenCLI","slug":"midjourney-cancel-request-failed-errormessage-e","errorCode":null,"errorMessage":"Midjourney cancel request failed: ${errorMessage(error)}","messagePattern":"Midjourney cancel request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":369,"sourceCode":"  if (!job && !allowMissing) {\n    throw new EmptyResultError('midjourney status', `Job ${jobId} was not found in the current account.`);\n  }\n  return job;\n}\n\nexport async function cancelMidjourneyJob(page, jobId) {\n  let result;\n  try {\n    result = unwrapEvaluateResult(await page.evaluate(async (id) => {\n      const response = await fetch('/api/job-cancel', {\n        method: 'POST',\n        headers: { 'Content-Type': 'application/json', 'X-CSRF-Protection': '1' },\n        body: JSON.stringify({ job_id: id }),\n      });\n      return { ok: response.ok, status: response.status, body: await response.text() };\n    }, jobId));\n  } catch (error) {\n    throw new CommandExecutionError(`Midjourney cancel request failed: ${errorMessage(error)}`);\n  }\n  if (!result?.ok) {\n    if ([401, 403].includes(Number(result?.status))) {\n      throw new AuthRequiredError(MIDJOURNEY_DOMAIN, 'Log into Midjourney in Chrome, then retry.');\n    }\n    throw new CommandExecutionError(\n      `Midjourney cancel request failed: HTTP ${result?.status ?? 0}${result?.body ? ` ${result.body}` : ''}`,\n    );\n  }\n  return result;\n}\n\nexport async function getVisibleJobIds(page) {\n  const payload = unwrapEvaluateResult(await page.evaluate(() => {\n    const ids = new Set();\n    for (const link of document.querySelectorAll('a[href*=\"/jobs/\"]')) {\n      const match = String(link.getAttribute('href') || '').match(/\\/jobs\\/([0-9a-f-]{36})/i);\n      if (match) ids.add(match[1].toLowerCase());","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L351-L387","documentation":"cancelMidjourneyJob issues an in-page fetch to Midjourney's cancel endpoint with the job ID. If the browser-side fetch itself throws (network failure, page navigation, CSP block, JSON serialization error), the function wraps the underlying error message into CommandExecutionError. It covers request-level failures, not HTTP error statuses (those are handled after the fetch resolves).","triggerScenarios":"Calling cancelMidjourneyJob while the Chrome page is navigating/closed, network interruption mid-request, the cancel endpoint URL failing to resolve, or the injected fetch throwing (e.g. blocked by CSP or invalid CSRF headers).","commonSituations":"Closing or reloading the Midjourney tab while the CLI is running; VPN/proxy dropping the connection; Midjourney changing the cancel endpoint path so the injected fetch hits a 404 route that redirects; stale page context after long idle sessions.","solutions":["Retry cancelMidjourneyJob in a fresh, loaded midjourney.com page/tab.","Check network connectivity and any proxy/VPN interfering with the browser request.","Confirm the cancel endpoint path/headers still match the current Midjourney site (inspect DevTools network tab for a manual cancel).","Read the wrapped errorMessage in the thrown error for the root cause and address it specifically."],"exampleFix":"// before\ntry {\n  await cancelMidjourneyJob(page, jobId);\n} catch (e) { /* generic handling */ }\n// after\ntry {\n  await cancelMidjourneyJob(page, jobId);\n} catch (e) {\n  await page.reload({ waitUntil: 'networkidle' }); // refresh stale page context\n  await cancelMidjourneyJob(page, jobId); // retry once on transient request failure\n}","handlingStrategy":"try-catch","validationCode":"// ensure page is on midjourney.com and still alive before cancelling\nif (page.isClosed()) throw new Error('Browser page closed; reopen midjourney.com');\nif (!page.url().includes('midjourney.com')) throw new Error('Navigate to midjourney.com before cancelling');","typeGuard":null,"tryCatchPattern":"try {\n  await cancelMidjourneyJob(page, jobId);\n} catch (e) {\n  if (String(e.message).includes('cancel request failed')) {\n    await page.reload({ waitUntil: 'networkidle' }); // recover stale page/network\n    await cancelMidjourneyJob(page, jobId);\n  } else throw e;\n}","preventionTips":["Keep the driven tab open and on midjourney.com for the duration of operations","Avoid cancelling during page navigation or while other in-page fetches run","Check VPN/proxy stability for long-running sessions","Read the wrapped root-cause message before retrying blindly"],"tags":["midjourney","network","cancel-request"],"backgroundTag":"request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}