jackwener/OpenCLI · error · CommandExecutionError

Midjourney subscription endpoint returned a malformed payloa

Error message

Midjourney subscription endpoint returned a malformed payload

What it means

getMidjourneyAccount validates the response of GET /api/subscriptions-check and throws CommandExecutionError if the payload is not a plain object (null, array, or non-object). The endpoint responded but returned data the CLI cannot interpret as an account record, so it aborts rather than dereferencing undefined fields.

Source

Thrown at clis/midjourney/utils.js:291

async function midjourneyJson(page, endpoint, options = {}) {
  try {
    return await page.fetchJson(endpoint, {
      ...options,
      headers: { ...CSRF_HEADERS, ...(options.headers || {}) },
    });
  } catch (error) {
    const message = errorMessage(error);
    if (/HTTP\s+(401|403)|unauthori[sz]ed|login|sign in/i.test(message)) {
      throw new AuthRequiredError(MIDJOURNEY_DOMAIN, 'Log into Midjourney in Chrome, then retry.');
    }
    throw new CommandExecutionError(`Midjourney API request failed: ${message}`);
  }
}

export async function getMidjourneyAccount(page) {
  const account = await midjourneyJson(page, '/api/subscriptions-check');
  if (!account || typeof account !== 'object' || Array.isArray(account)) {
    throw new CommandExecutionError('Midjourney subscription endpoint returned a malformed payload');
  }
  if (!account.user_id) {
    throw new AuthRequiredError(MIDJOURNEY_DOMAIN, 'Log into Midjourney in Chrome, then retry.');
  }
  return account;
}

export function assertGenerationEntitlement(account) {
  if (account.status !== 'active' || !account.plan?.type) {
    throw new CommandExecutionError(
      'Midjourney generation requires an active subscription.',
      `Check the account at ${MIDJOURNEY_URL}/account.`,
    );
  }
  const remaining = Number(account.total_credits ?? account.credits_total ?? 0);
  if (!(remaining > 0) && !account.abilities?.can_relax) {
    throw new CommandExecutionError(
      'No Midjourney generation credits remain for this billing period.',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log the raw response body of /api/subscriptions-check to see what was actually returned.
  2. Re-authenticate in Chrome and retry — challenge pages often cause malformed payloads.
  3. Check for Midjourney API changes and update the CLI's expected response shape.
  4. Retry after a delay if Cloudflare was throttling the request.

Example fix

// before
const account = await getMidjourneyAccount(page);
// after
const raw = await midjourneyJson(page, '/api/subscriptions-check');
console.debug('payload', raw);
const account = await getMidjourneyAccount(page);
Defensive patterns

Strategy: type-guard

Validate before calling

const raw = await midjourneyJson(page, '/api/subscriptions-check');
if (raw == null || typeof raw !== 'object' || Array.isArray(raw)) console.error('unexpected subscriptions-check payload', raw);

Type guard

function isAccountPayload(value) {
  return value != null && typeof value === 'object' && !Array.isArray(value);
}

Try / catch

try {
  const account = await getMidjourneyAccount(page);
} catch (err) {
  if (/malformed payload/.test(err.message)) {
    console.error('subscriptions-check returned unexpected data; re-authenticate and retry.');
  } else throw err;
}

Prevention

When it happens

Trigger: midjourneyJson(page, '/api/subscriptions-check') resolves to null, an Array, or a primitive — e.g. the endpoint returns an HTML login interstitial parsed oddly, an empty body, or an error JSON lacking the expected shape.

Common situations: Midjourney API contract changes, Cloudflare challenge pages returned as non-JSON, partially authenticated sessions returning empty payloads, or hitting the wrong endpoint during API version drift.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/0a09878ccd90437d. Report an issue: GitHub.