Commit 2f7a3b05a9
Unsigned
Layout: unified · split
api/src/lib/page.ts +2 −1
| @@ -109,7 +109,8 @@ export const fetchPage = async (target: string): Promise<Page> => { | |||
| 109 | url = new URL(location, url) | 109 | url = new URL(location, url) |
| 110 | continue | 110 | continue |
| 111 | } | 111 | } |
| 112 | if (!res.ok) { | 112 | // Only a 200 is the page itself, other 2xx are interstitials |
| 113 | if (res.status !== 200) { | ||
| 113 | throw new ApiError( | 114 | throw new ApiError( |
| 114 | 'UPSTREAM_ERROR', | 115 | 'UPSTREAM_ERROR', |
| 115 | `${url.hostname} returned ${res.status}`, | 116 | `${url.hostname} returned ${res.status}`, |
api/tests/trackers.test.ts +3 −2
| @@ -221,8 +221,8 @@ describe('isPrivateIp', () => { | |||
| 221 | }) | 221 | }) |
| 222 | }) | 222 | }) |
| 223 | 223 | ||
| 224 | const html = (body: BodyInit) => | 224 | const html = (body: BodyInit, status = 200) => |
| 225 | new Response(body, { headers: { 'content-type': 'text/html' } }) | 225 | new Response(body, { status, headers: { 'content-type': 'text/html' } }) |
| 226 | const redirect = (location: string) => | 226 | const redirect = (location: string) => |
| 227 | new Response(null, { status: 301, headers: { location } }) | 227 | new Response(null, { status: 301, headers: { location } }) |
| 228 | 228 | ||
| @@ -285,6 +285,7 @@ describe('fetchPage', () => { | |||
| 285 | it('rejects error statuses, non-HTML and network failures as 502', async () => { | 285 | it('rejects error statuses, non-HTML and network failures as 502', async () => { |
| 286 | for (const respond of [ | 286 | for (const respond of [ |
| 287 | async () => new Response('nope', { status: 404 }), | 287 | async () => new Response('nope', { status: 404 }), |
| 288 | async () => html('<p>hi</p>', 202), | ||
| 288 | async () => | 289 | async () => |
| 289 | new Response('%PDF', { headers: { 'content-type': 'application/pdf' } }), | 290 | new Response('%PDF', { headers: { 'content-type': 'application/pdf' } }), |
| 290 | async () => Promise.reject(new TypeError('fetch failed')), | 291 | async () => Promise.reject(new TypeError('fetch failed')), |