pot-app/pot-desktop · error · Error

Http Request Error Http Status: ${res.status} ${JSON.stringi

Error message

Http Request Error
Http Status: ${res.status}
${JSON.stringify(res.data)}

What it means

The Cambridge Dictionary translate service throws this when the HTTP response from dictionary.cambridge.org comes back with a non-2xx status. It wraps the status code and the raw response body in the message so the developer can see exactly what the server rejected and why. It is a generic guard for any upstream HTTP failure (network-level errors are thrown separately by the Tauri fetch).

Source

Thrown at src/services/translate/cambridge_dict/index.jsx:53

    if (Language.auto === from) {
        from = tryDetectLanguage(text) ?? from;
    }
    // only supports English word translation
    if (from !== Language.en || to === undefined || to === from || text.split(' ').length > 1) {
        return '';
    }

    const url = `https://dictionary.cambridge.org/search/direct/?datasetsearch=${from}-${to}&q=${text}`;
    let res = await fetch(url, {
        method: 'GET',
        headers: {
            'Content-Type': 'text/html;charset=UTF-8',
        },
        responseType: 2,
    });

    if (!res.ok) {
        throw new Error(`Http Request Error\nHttp Status: ${res.status}\n${JSON.stringify(res.data)}`);
    }
    const doc = new DOMParser().parseFromString(res.data, 'text/html');
    const entryNodes = doc.querySelectorAll('.pr.entry-body__el');
    if (entryNodes.length === 0) {
        throw new Error(`Words not yet included: ${text}`);
    }

    const resultMap = [...entryNodes].reduce((dict, entryNode) => {
        const wordTranslateResult = dict['result'] || new WordTranslateResult([], []);

        if (wordTranslateResult.pronunciations.length === 0) {
            const pronunciationNodes = entryNode.querySelectorAll('.dpron-i');
            const pronunciations = [...pronunciationNodes].map((pronunciationNode) => {
                const region = pronunciationNode.querySelector('.region').innerText;
                const symbol = pronunciationNode.querySelector('.pron').innerText;
                let voice = pronunciationNode.querySelector('.daud source').src;
                voice = voice.replace(/^https?:\/\/[^/]+/, 'https://dictionary.cambridge.org');
                voice = voice.replace(/^tauri:\/\/[^/]+/, 'https://dictionary.cambridge.org');

View on GitHub (pinned to 594d32ede9)

Solutions

  1. Check the status code in the message: 403/429 usually means bot detection or rate limiting — retry later or add a valid User-Agent header in the fetch call.
  2. Verify network/proxy connectivity to dictionary.cambridge.org in a browser; if blocked, fix proxy/VPN settings.
  3. 5xx statuses mean a Cambridge-side outage — wait and retry.
  4. Confirm the `from`/`to` language pair is a valid Cambridge dataset (e.g. en-zh); invalid pairs can yield 4xx.

Example fix

// before
const res = await fetch(url, { method: 'GET', headers: { 'Content-Type': 'text/html;charset=UTF-8' }, responseType: 2 });
// after
const res = await fetch(url, {
  method: 'GET',
  headers: {
    'Content-Type': 'text/html;charset=UTF-8',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36',
  },
  responseType: 2,
});
Defensive patterns

Strategy: try-catch

Validate before calling

const isSingleEnglishWord = (text) => /^[A-Za-z][A-Za-z'-]*$/.test(text.trim());
if (!isSingleEnglishWord(text)) return ''; // skip fetch entirely for invalid input
if (!navigator.onLine) return '';

Type guard

function isFetchResponse(res) {
  return res && typeof res.ok === 'boolean' && typeof res.status === 'number';
}

Try / catch

try {
  const result = await cambridgeTranslate(text, from, to);
} catch (e) {
  if (String(e.message).startsWith('Http Request Error')) {
    // network/HTTP failure: fall back to another service or show retry UI
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling translate(text, from, to) in src/services/translate/cambridge_dict/index.jsx:34 when the GET to https://dictionary.cambridge.org/search/direct/?datasetsearch=<from>-<to>&q=<text> returns res.ok === false (e.g. 403 bot-block, 429 rate limit, 5xx outage).

Common situations: Cambridge CDN/WAF blocks the request (no browser User-Agent), the user is offline or behind a proxy that returns an error page, Cambridge changes its URL scheme, or rate limiting kicks in after many dictionary lookups in a short time.

Related errors


AI-assisted analysis of pot-app/pot-desktop@594d32ede9 (2026-09-02). Data as JSON: /api/errors/3aab6759a5910276. Report an issue: GitHub.