(
route,
{ headers, allow500s, allow404 } = {
headers: undefined,
allow500s: false,
allow404: false,
}
)
| 69 | } |
| 70 | |
| 71 | export async function getDOM( |
| 72 | route, |
| 73 | { headers, allow500s, allow404 } = { |
| 74 | headers: undefined, |
| 75 | allow500s: false, |
| 76 | allow404: false, |
| 77 | } |
| 78 | ) { |
| 79 | const res = await get(route, { followRedirects: true, headers }) |
| 80 | if (!allow500s && res.status >= 500) { |
| 81 | throw new Error(`Server error (${res.status}) on ${route}`) |
| 82 | } |
| 83 | if (!allow404 && res.status === 404) { |
| 84 | throw new Error(`Page not found on ${route}`) |
| 85 | } |
| 86 | const $ = cheerio.load(res.text || '', { xmlMode: true }) |
| 87 | $.res = Object.assign({}, res) |
| 88 | return $ |
| 89 | } |
| 90 | |
| 91 | // For use with the ?json query param |
| 92 | // e.g. await getJSON('/en?json=breadcrumbs') |
no test coverage detected