(route, opts)
| 91 | // For use with the ?json query param |
| 92 | // e.g. await getJSON('/en?json=breadcrumbs') |
| 93 | export async function getJSON(route, opts) { |
| 94 | const res = await get(route, { ...opts, followRedirects: true }) |
| 95 | if (res.status >= 500) { |
| 96 | throw new Error(`Server error (${res.status}) on ${route}`) |
| 97 | } |
| 98 | if (res.status >= 400) { |
| 99 | console.warn(`${res.status} on ${route} and the response might not be JSON`) |
| 100 | } |
| 101 | return JSON.parse(res.text) |
| 102 | } |
no test coverage detected