{"record":{"id":"4d0ba1c448a4bd96","repo":"jackwener/OpenCLI","slug":"log-into-midjourney-in-chrome-then-retry","errorCode":null,"errorMessage":"Log into Midjourney in Chrome, then retry.","messagePattern":"Log into Midjourney in Chrome, then retry\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":282,"sourceCode":"  if (!raw) throw new ArgumentError('--output cannot be empty');\n  const expanded = raw === '~' ? os.homedir() : raw.startsWith('~/') ? path.join(os.homedir(), raw.slice(2)) : raw;\n  return path.resolve(expanded);\n}\n\nfunction errorMessage(error) {\n  return error instanceof Error ? error.message : String(error);\n}\n\nasync function midjourneyJson(page, endpoint, options = {}) {\n  try {\n    return await page.fetchJson(endpoint, {\n      ...options,\n      headers: { ...CSRF_HEADERS, ...(options.headers || {}) },\n    });\n  } catch (error) {\n    const message = errorMessage(error);\n    if (/HTTP\\s+(401|403)|unauthori[sz]ed|login|sign in/i.test(message)) {\n      throw new AuthRequiredError(MIDJOURNEY_DOMAIN, 'Log into Midjourney in Chrome, then retry.');\n    }\n    throw new CommandExecutionError(`Midjourney API request failed: ${message}`);\n  }\n}\n\nexport async function getMidjourneyAccount(page) {\n  const account = await midjourneyJson(page, '/api/subscriptions-check');\n  if (!account || typeof account !== 'object' || Array.isArray(account)) {\n    throw new CommandExecutionError('Midjourney subscription endpoint returned a malformed payload');\n  }\n  if (!account.user_id) {\n    throw new AuthRequiredError(MIDJOURNEY_DOMAIN, 'Log into Midjourney in Chrome, then retry.');\n  }\n  return account;\n}\n\nexport function assertGenerationEntitlement(account) {\n  if (account.status !== 'active' || !account.plan?.type) {","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L264-L300","documentation":"midjourneyJson wraps all HTTP errors; when the error message matches /HTTP\\s+(401|403)|unauthorized|login|sign in/i it raises AuthRequiredError instead of a generic CommandExecutionError. It signals the Midjourney cookies in Chrome are missing or expired and the request was not authenticated. The user must log in interactively.","triggerScenarios":"Any midjourneyJson call (account, payload, history) whose underlying request fails with HTTP 401/403 or an error message mentioning login/sign-in/unauthorized.","commonSituations":"Midjourney session cookie expired after weeks of inactivity, using a fresh Chrome profile that never logged in, VPN/IP change invalidating the session, or Midjourney rotating CSRF/session requirements.","solutions":["Open Chrome, log into midjourney.com, verify the dashboard loads, then rerun the command.","Confirm the CLI is pointed at the same Chrome profile that holds the session.","Clear stale cookies for midjourney.com and log in again if a corrupted session persists.","Disable conflicting VPN/proxy that may invalidate the session, then re-authenticate."],"exampleFix":"// before\nawait midjourneyJson(page, '/api/subscriptions-check'); // throws AuthRequiredError\n// after\nconst account = await getMidjourneyAccount(page).catch(async (e) => {\n  if (e instanceof AuthRequiredError) { await interactiveLogin(page); return getMidjourneyAccount(page); }\n  throw e;\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAuthRequiredError(err) {\n  return err != null && typeof err === 'object' &&\n    (/HTTP\\s+(401|403)|unauthori[sz]ed|login|sign in/i.test(String(err.message)) || err.constructor?.name === 'AuthRequiredError');\n}","tryCatchPattern":"try {\n  const account = await midjourneyJson(page, '/api/subscriptions-check');\n} catch (err) {\n  if (isAuthRequiredError(err)) {\n    console.error('Session expired. Open Chrome, log into midjourney.com, then retry.');\n    process.exitCode = 2; // distinct code for auth failures\n  } else throw err;\n}","preventionTips":["Re-login to midjourney.com periodically; sessions expire","Pin the CLI to a dedicated Chrome profile that stays logged in","Detect AuthRequiredError and surface an actionable message instead of retrying","Avoid IP/VPN churn that can invalidate sessions"],"tags":["midjourney","authentication","http-401","http-403"],"backgroundTag":"auth-required-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}