{"record":{"id":"dfdb60669933687f","repo":"badges/shields","slug":"e-message","errorCode":null,"errorMessage":"${e.message}","messagePattern":"\\$\\{e\\.message\\}","errorType":"exception","errorClass":"InvalidResponse","httpStatus":null,"severity":"error","filePath":"services/dynamic/dynamic-xml.service.js","lineNumber":89,"sourceCode":"  }\n\n  static defaultBadgeData = { label: 'custom badge' }\n\n  getmimeType(contentType) {\n    return MIME_TYPES.find(mime => contentType.includes(mime)) ?? 'text/xml'\n  }\n\n  transform({ pathExpression, buffer, contentType = 'text/xml' }) {\n    // e.g. //book[2]/@id\n    const pathIsAttr = (\n      pathExpression.split('/').slice(-1)[0] || ''\n    ).startsWith('@')\n\n    let parsed\n    try {\n      parsed = new DOMParser().parseFromString(buffer, contentType)\n    } catch (e) {\n      throw new InvalidResponse({ prettyMessage: e.message })\n    }\n\n    let values\n    try {\n      if (contentType === 'text/html') {\n        values = xpath\n          .parse(pathExpression)\n          .select({ node: parsed, isHtml: true })\n      } else {\n        values = xpath.select(pathExpression, parsed)\n      }\n    } catch (e) {\n      throw new InvalidParameter({ prettyMessage: e.message })\n    }\n\n    if (\n      typeof values === 'string' ||\n      typeof values === 'number' ||","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/dynamic/dynamic-xml.service.js#L71-L107","documentation":"Thrown by the dynamic-xml service's transform when new DOMParser().parseFromString(buffer, contentType) throws, and the original exception's message is surfaced as an InvalidResponse. This means the fetched document could not be parsed as the given content type (XML/HTML) — typically malformed markup or a non-XML response. Note that XML parse errors may surface here or as values-less downstream failures depending on the parser implementation.","triggerScenarios":"The url returns content that fails DOM parsing with the declared contentType: truncated XML, HTML when XML parsing was selected, a JSON or plain-text error page, or an encoding problem that breaks the parser.","commonSituations":"API outage returning an HTML error page; wrong url pointing at JSON instead of XML; missing/incorrect Content-Type handling; CDATA/entity issues in the upstream document.","solutions":["Fetch the url and validate the document is well-formed XML/HTML (xmllint or an online validator).","Ensure the contentType matches the actual response (use text/html for HTML documents).","Check the upstream API status — an error page is often the real cause.","Verify encoding/escaping of the url and response (UTF-8)."],"exampleFix":"// before\nurl=https://api.example.com/data.json parsed as XML\n// after\nurl=https://api.example.com/data.xml (or switch service to dynamic/json)","handlingStrategy":"validation","validationCode":"function looksLikeXml(s) {\n  const t = s.trim();\n  return t.startsWith('<') && !t.startsWith('<!DOCTYPE html') && /<\\/?[\\w:-]+[\\s\\S]*/.test(t);\n}\nconst body = await fetch(url).then(r => r.text());\nif (!looksLikeXml(body)) throw new Error('url does not return XML');","typeGuard":"function isHtmlContentType(ct) { return /^text\\/html/i.test(ct || ''); }\nfunction isXmlLike(body) { return typeof body === 'string' && body.trim().startsWith('<?xml'); }","tryCatchPattern":"try {\n  const value = await dynamicXml({ url, path, contentType });\n} catch (err) {\n  // InvalidResponse wrapping parser error message — check the upstream response\n  console.error('XML parse failed:', err.message);\n  throw err;\n}","preventionTips":["Validate upstream documents are well-formed XML (xmllint) before wiring a dynamic-xml badge.","Match contentType to the actual response format (text/html for HTML docs).","Monitor the upstream API — HTML error pages during outages cause parse failures."],"tags":["xml","parsing","upstream-response","dynamic-badge"],"backgroundTag":"xml-parse-error","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}