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 | 109 | url = new URL(location, url) |
| 110 | 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 | 114 | throw new ApiError( |
| 114 | 115 | 'UPSTREAM_ERROR', |
| 115 | 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) => | |
| 225 | new Response(body, { headers: { 'content-type': 'text/html' } }) | |
| 224 | const html = (body: BodyInit, status = 200) => | |
| 225 | new Response(body, { status, headers: { 'content-type': 'text/html' } }) | |
| 226 | 226 | const redirect = (location: string) => |
| 227 | 227 | new Response(null, { status: 301, headers: { location } }) |
| 228 | 228 | |
| @@ -285,6 +285,7 @@ describe('fetchPage', () => { | ||
| 285 | 285 | it('rejects error statuses, non-HTML and network failures as 502', async () => { |
| 286 | 286 | for (const respond of [ |
| 287 | 287 | async () => new Response('nope', { status: 404 }), |
| 288 | async () => html('<p>hi</p>', 202), | |
| 288 | 289 | async () => |
| 289 | 290 | new Response('%PDF', { headers: { 'content-type': 'application/pdf' } }), |
| 290 | 291 | async () => Promise.reject(new TypeError('fetch failed')), |