mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Parse Lithuania catalogs inside the shared reader so bad JSON cancels the sibling
This commit is contained in:
1 parent
b6d5d7373f
commit
247452c202
3 files changed
+42
-38
No files matched your search
@@ -4,19 +4,21 @@ import { readResponseTextCapped } from '../common/http.js';
|
||||
* Read catalogs that are only useful together, because the pack joins them.
|
||||
*
|
||||
* The requests share one deadline and refuse redirects. Whichever fails first
|
||||
* (before its headers, on its status, or while its capped body is read) aborts
|
||||
* the others at once, so a stalled feed is not waited on until the deadline.
|
||||
* Every response body is released, including one that arrives after another
|
||||
* feed has already failed.
|
||||
* (before its headers, on its status, or while its capped body is read or
|
||||
* parsed) aborts the others at once, so a stalled feed is not waited on until
|
||||
* the deadline. Every response body is released, including one that arrives
|
||||
* after another feed has already failed.
|
||||
*
|
||||
* @param {Array<{url: string, label: string}>} feeds `label` names the feed
|
||||
* in the error ("locations download failed: 503").
|
||||
* @param {{accept: string, maxBytes: number, timeoutMs: number}} options
|
||||
* @returns {Promise<string[]>} The body texts, in feed order.
|
||||
* @param {{accept: string, maxBytes: number, timeoutMs: number,
|
||||
* parse?: (text: string) => unknown}} options
|
||||
* @returns {Promise<unknown[]>} The parsed bodies (texts without `parse`), in
|
||||
* feed order.
|
||||
*/
|
||||
export async function readCatalogsTogether(
|
||||
feeds,
|
||||
{ accept, maxBytes, timeoutMs },
|
||||
{ accept, maxBytes, timeoutMs, parse = (text) => text },
|
||||
) {
|
||||
const sibling = new AbortController();
|
||||
const signal = AbortSignal.any([
|
||||
@@ -40,7 +42,7 @@ export async function readCatalogsTogether(
|
||||
: `${label} download failed: ${response.status}`,
|
||||
);
|
||||
}
|
||||
return await readResponseTextCapped(response, maxBytes, signal);
|
||||
return parse(await readResponseTextCapped(response, maxBytes, signal));
|
||||
} catch (error) {
|
||||
sibling.abort();
|
||||
await response?.body?.cancel().catch(() => {});
|
||||
|
||||
Reference in new issue
Block a user