santifer/career-ops · error · Error

itviec: URL must use HTTPS

Error message

itviec: URL must use HTTPS: ${url}

What it means

assertItviecUrl requires the https: protocol; itviec content is only fetched over TLS. Any http:// URL — even one with the correct hostname — is rejected with this error to prevent downgrade/MITM of scraped content.

Solutions

  1. Change the scheme to https:// in the URL/portals.yml entry
  2. Prefer https by default when constructing URLs in code (e.g. `https://${host}${path}` instead of `${scheme}://${host}`)
  3. If the site redirects http->https, link directly to the https canonical URL

Example fix

// before
assertItviecUrl('http://www.itviec.com/it-jobs');
// after
assertItviecUrl('https://www.itviec.com/it-jobs');
Defensive patterns

Strategy: validation

Validate before calling

function isHttpsUrl(url) {
  try { return new URL(url).protocol === 'https:'; } catch { return false; }
}
// check before calling: if (!isHttpsUrl(entry.careers_url)) upgrade or skip;

Type guard

const isHttps = (u) => { try { return new URL(u).protocol === 'https:'; } catch { return false; } };

Try / catch

try {
  assertItviecUrl(url);
} catch (err) {
  if (/must use HTTPS/.test(err.message)) {
    const upgraded = url.replace(/^http:/, 'https:');
    return assertItviecUrl(upgraded); // one retry after scheme fix
  }
  throw err;
}

Prevention

When it happens

Trigger: A portals.yml entry (or test URL) uses http:// instead of https:// for an itviec.com URL and is passed through assertItviecUrl.

Common situations: Config copied from an old pre-HTTPS link; a manual edit dropped the 's'; a redirect target (http URL captured from logs) was pasted back into config.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/fd8b2fad7e9d6cae. Report an issue: GitHub.

Appendix: source

Thrown at providers/itviec.mjs:84

/** Relative publication label: English "Posted … ago" or Vietnamese "Đăng … trước". */
const POSTED_LABEL_RE =
  /(?:Posted|Đăng)\s*:?\s*(?:<\/\w+>\s*)?([^.<]{0,40}?(?:ago|trước)|today|hôm nay)/i;

/** @param {any} ctx @param {number} ms */
function sleep(ctx, ms) {
  if (typeof ctx?.sleep === 'function') return ctx.sleep(ms);
  return new Promise((r) => setTimeout(r, ms));
}

/** @param {string} url */
function assertItviecUrl(url) {
  let parsed;
  try {
    parsed = new URL(url);
  } catch {
    throw new Error(`itviec: invalid URL: ${url}`);
  }
  if (parsed.protocol !== 'https:') throw new Error(`itviec: URL must use HTTPS: ${url}`);
  if (parsed.hostname !== TRUSTED_HOST) {
    throw new Error(`itviec: untrusted hostname "${parsed.hostname}" — must be ${TRUSTED_HOST}`);
  }
  return url;
}

/**
 * Collapse a markup fragment to its visible text.
 * @param {string} fragment
 * @returns {string}
 */
export function visibleText(fragment) {
  return decodeEntities(
    String(fragment ?? '')
      .replace(/<!--[\s\S]*?-->/g, ' ')
      .replace(/<[^>]+>/g, ' '),
  )
    .replace(/\s+/g, ' ')

View on GitHub (pinned to aac998c7ed)