Repository navigation
refactor(data-api): tag jsonFetch outcomes instead of collapsing to null - #33
Merged
neuromechanist merged 2 commits intoMay 19, 2026
Conversation
Replaces the unconditional T|null contract of jsonFetch with a
FetchOutcome<T> discriminated union covering: ok, not_found,
rate_limited, upstream_error, timeout, network_error, parse_error.
Every previously-throwing path (AbortError, JSON parse, network/DNS
failures) is now caught + tagged so callers can distinguish "the
resource genuinely doesn't exist" from "the data layer is degraded."
Legacy T|null API preserved via jsonFetchOrNull (used by the four
existing getX helpers); new *Outcome variants are introduced for
callers that need the discriminant.
Behavioral changes (user-visible):
- /dataset/<id> SSR: real 404 only when BOTH landing and metadata are
not_found. Degraded responses (timeout, 5xx, parse error) now return
503 instead of silently 404ing, so monitoring distinguishes typo'd
URLs from data-layer outages.
- /api/dataset/<id>/{readme,tree}: explicit 404 when landing is
not_found, short-circuiting the manifest fall-through that would
otherwise render a misleading "no manifest" state for missing
datasets.
Also sweeps the archiveZipUrl comment drift flagged on PR #31 — the
old comment referenced a `download/<id>/<v>.zip` path that doesn't
exist in the code.
Closes #32.
5 tasks
Deploying nemar-website with
|
| Latest commit: |
302cdd6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://527b12a6.nemar-website.pages.dev |
| Branch Preview URL: | https://32-refactor-jsonfetch-to-dis.nemar-website.pages.dev |
Critical:
- Cache-Control on the Response object, not Astro.response. Astro returns
the inner Response verbatim, so headers set on Astro.response never
reached the edge and Cloudflare was free to cache the transient 404s
and 503s. (silent-failure 2)
Important:
- metadata not_found is no longer a 503. metadata.json is OPTIONAL on
the data side — a fresh dataset can have landing without metadata yet.
Only landing not_found (alone) is a partial-publish degradation. New
pure helper resolveDatasetPageStatus encapsulates the 9-cell decision
table; tests cover every combination. (code-reviewer 1, test-analyzer 1)
- 429 retry now bails on parent abort during the Retry-After sleep so
caller cancellation doesn't burn the full delay. Parent-aborts also
map to network_error("request cancelled by caller") instead of
masquerading as timeout in logs. (code-reviewer 2, silent-failure 1)
- Safety-net 500 path now console.errors + sets Cache-Control: no-store
before returning. (silent-failure 3)
- resolveCanonical logs non-404 errors instead of silently swallowing
them. (silent-failure 4)
- outcomeValue exhaustiveness test now uses `satisfies Exclude<
FetchOutcome<unknown>, {kind:"ok"}>[]` so adding a new outcome kind
forces an explicit test case. (test-analyzer 3)
Comments:
- Dropped redundant JSDocs on outcomeValue + the first sentence of
jsonFetch (both restated the type signature). (comment-analyzer 1, 2)
- "Legacy" removed from the section divider comment — both T|null and
*Outcome variants are first-class now, not deprecated. (comment 4)
- SSR-page comment explains the 404-asymmetry WHY (only confirmed when
both signals agree). (comment 3)
Contributor
Author
Review findings addressed (commit 302cdd6)Critical:
Important — correctness:
Important — testability:
Comments:
Deferred / declined:
Net result: 143 tests pass (7 new for resolveDatasetPageStatus + 1 anchored exhaustiveness), typecheck clean, biome clean on changed files, build clean. |
neuromechanist
deleted the
32-refactor-jsonfetch-to-distinguish-error-types-timeout-vs-404-vs-5xx-vs-parse-error
branch
May 19, 2026 04:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the unconditional `T | null` contract of `jsonFetch` with a `FetchOutcome` discriminated union covering every failure mode: `ok`, `not_found`, `rate_limited`, `upstream_error`, `timeout`, `network_error`, `parse_error`. Every previously-throwing path (`AbortError`, JSON parse, network/DNS failures) is now caught + tagged so callers can distinguish "the resource genuinely doesn't exist" from "the data layer is degraded."
Why
Deferred from PR #30 and PR #31 review threads — silent-failure-hunter flagged the same root cause in both: `jsonFetch` callers couldn't tell whether `null` meant 404, timeout, 5xx, malformed JSON, or a network failure, and several error paths (AbortError, SyntaxError) actually propagated as unhandled exceptions to surface as 500s with no signal.
What changed
`src/lib/data-api.ts`:
Behavioral changes (user-visible):
Test plan
Notes