santifer/career-ops · error · Error

wttj: invalid URL: ${url}

Error message

wttj: invalid URL: ${url}

What it means

assertHost pins WTTJ/Algolia URLs to expected https hosts. This branch fires when new URL(url) throws. In production this is only reachable if ENV_URL is malformed, or — defensively — if appId validation let an unparseable Algolia host through (it cannot, given the ^[A-Z0-9]{6,16}$i guard on appId).

Source

Thrown at providers/wttj.mjs:38

//     enabled: true
//
// Each hit maps to the normalized Job shape; salary_yearly_minimum (when
// present) is attached as `salary: {min, max, currency}` so scan.mjs's
// salary_filter can gate on it.

const ENV_URL = 'https://www.welcometothejungle.com/api/env';
const SITE_ORIGIN = 'https://www.welcometothejungle.com';
const INDEX = 'wttj_jobs_production_en';
const DEFAULT_MAX_HITS = 100;
const MAX_HITS_CAP = 200;

/** Pin a URL to an expected https host. */
function assertHost(url, host, label) {
  let parsed;
  try {
    parsed = new URL(url);
  } catch {
    throw new Error(`wttj: invalid URL: ${url}`);
  }
  if (parsed.protocol !== 'https:') throw new Error(`wttj: URL must use HTTPS: ${url}`);
  if (parsed.hostname !== host.toLowerCase()) {
    throw new Error(`wttj: untrusted ${label} hostname "${parsed.hostname}" — must be ${host}`);
  }
  return url;
}

/**
 * Parse the `window.env = {...}` payload served by /api/env and extract the
 * Algolia application id + client search key.
 * @param {string} text
 * @returns {{ appId: string, apiKey: string }}
 */
export function parseEnvPayload(text) {
  const start = text.indexOf('{');
  const end = text.lastIndexOf('}');
  if (start === -1 || end <= start) throw new Error('wttj: /api/env payload has no JSON object');

View on GitHub (pinned to 9b17a8ac97)

Solutions

  1. Restore ENV_URL to https://www.welcometothejungle.com/api/env.
  2. Keep the appId regex so algoliaHost is always well-formed.

Example fix

// before
const ENV_URL = 'www.welcometothejungle.com/api/env';
// after
const ENV_URL = 'https://www.welcometothejungle.com/api/env';
Defensive patterns

Strategy: validation

Validate before calling

try { new URL(ENV_URL); }
catch { throw new Error(`wttj: ENV_URL constant is malformed: ${ENV_URL}`); }

Type guard

const isAbsoluteUrl = (s) => { try { new URL(s); return true; } catch { return false; } };

Prevention

When it happens

Trigger: A maintainer breaks the ENV_URL constant; an empty appId is interpolated into the algolia host (defensive — the app-id regex already prevents this).

Common situations: Refactor of ENV_URL; a bad merge.

Related errors


AI-assisted analysis of santifer/career-ops@9b17a8ac97 (2026-08-13). Data as JSON: /api/errors/6de7395a9a37a849. Report an issue: GitHub.