Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions runner/apps/authoring/src/docs-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ async function fetchDocsJson<T>(url: string, describe: string): Promise<T> {
try {
return (await res.json()) as T;
} catch (cause) {
// A connection cut mid-body is a transport failure, not a bad artifact, so it
// keeps its own error rather than being reported as unparseable JSON.
if (!(cause instanceof SyntaxError)) throw cause;
// A truncated or half-uploaded artifact served correctly as JSON. Left as a
// plain (transient) Error — the host does have the file — but re-thrown with
// `describe` so it still carries the bucket key. A bare `res.json()` reject
Expand Down
12 changes: 12 additions & 0 deletions runner/pipeline/docs-catalog.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ test("manifest: a truncated body served as application/json names the bucket and
assert.equal(error.cause instanceof Error, true);
});

test("manifest: a body stream cut by the network rethrows the transport error, not an unparseable-JSON one", async (t) => {
// The headers arrived as application/json but the connection died mid-body, so
// `res.json()` rejects with the browser's own `TypeError: Failed to fetch`.
const cut = new TypeError("Failed to fetch");
withFetch(t, () => ({ ...reply({ body: "" }), json: async () => { throw cut; } }));

const error = await rejection(fetchDocsManifest("net-cut"));

assert.equal(error, cut);
assert.equal(isDocsResourceMissing(error), false);
});

test("manifest: a 200 body that is neither HTML nor JSON rejects as non-missing", async (t) => {
withFetch(t, () => reply({ contentType: "text/plain", body: "not json at all" }));

Expand Down
Loading