decolua/9router · error

Xquik queryType must be Latest or Top

Error message

Xquik queryType must be Latest or Top

What it means

buildXquikRequest validates the optional `queryType` provider setting (read from providerOptions or providerSpecificData via getProviderSetting). Xquik's upstream API only accepts 'Latest' or 'Top'; any other non-empty string is rejected with this error before a request is built.

Source

Thrown at open-sse/handlers/search/callers.js:356

  const page = toPageNumber(params.offset, params.maxResults);
  if (page) qp.set("pageno", String(page));

  return {
    url: `${url}?${qp}`,
    init: {
      method: "GET",
      headers: { Accept: "application/json" },
    },
  };
}

function buildXquikRequest(config, params) {
  const apiKey = params.token;
  if (!apiKey) throw new Error("Xquik requires an API key");

  const queryType = getProviderSetting(params, "queryType");
  if (queryType && !["Latest", "Top"].includes(queryType)) {
    throw new Error("Xquik queryType must be Latest or Top");
  }

  const qp = new URLSearchParams({
    q: params.query,
    limit: String(params.maxResults),
  });
  const cursor = getProviderSetting(params, "cursor");
  if (cursor) qp.set("cursor", cursor);
  if (queryType) qp.set("queryType", queryType);
  if (params.language) qp.set("language", params.language);

  return {
    url: `${resolveBaseUrl(config, params)}?${qp}`,
    init: {
      method: "GET",
      headers: { Accept: "application/json", "x-api-key": apiKey },
    },
  };

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Use exactly 'Latest' or 'Top' (capitalized) in providerOptions.queryType
  2. Omit queryType entirely if you don't need it — it's optional and defaults upstream
  3. Normalize the value before calling: `const qt = v ? v[0].toUpperCase() + v.slice(1).toLowerCase() : undefined` and validate against the allowed list
  4. Check where the setting is persisted (providerSpecificData vs providerOptions) and correct the stale value

Example fix

// before
await search({ provider: 'xquik', query: 'ai', token, providerOptions: { queryType: 'latest' } });
// after
await search({ provider: 'xquik', query: 'ai', token, providerOptions: { queryType: 'Latest' } });
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED_QUERY_TYPES = ['Latest', 'Top'];
const qt = params.providerOptions?.queryType ?? params.providerSpecificData?.queryType;
if (qt !== undefined && !ALLOWED_QUERY_TYPES.includes(qt)) {
  throw new Error(`Xquik queryType must be one of ${ALLOWED_QUERY_TYPES.join(', ')}`);
}

Type guard

function isValidXquikQueryType(v) {
  return v === undefined || (typeof v === 'string' && ['Latest', 'Top'].includes(v));
}

Try / catch

try {
  const res = await search({ provider: 'xquik', query, token, providerOptions: { queryType } });
} catch (err) {
  if (err.message.includes('queryType must be')) {
    // fall back to omitting queryType (default behavior)
    return search({ provider: 'xquik', query, token });
  } else throw err;
}

Prevention

When it happens

Trigger: Passing providerOptions.queryType or providerSpecificData.queryType with a value other than 'Latest' or 'Top' (e.g. 'latest', 'recent', 'Live', 'mixed'). The check is case-sensitive.

Common situations: Client sends lowercase 'latest' while the API expects capitalized 'Latest'; UI/dashboard exposes a free-text field instead of a dropdown; typo like 'TopTweets' or 'trending'; stale saved settings from an older schema.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30). Data as JSON: /api/errors/52b8816356e7c45d. Report an issue: GitHub.