Skip to content

Handle the journal's 204 and JOURNAL_NOT_FOUND signals explicitly - #2

Merged
zprobs merged 3 commits into
mainfrom
journal-204-no-content
Oct 21, 2026
Merged

zprobs merged 3 commits into
mainfrom
journal-204-no-content

Conversation

@zprobs

@zprobs zprobs commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • The journal API returns 204 No Content with an empty body from /earliest and /latest when an app's journal is empty. It never returns 404 for that. The poller only worked because axios hands back "" for a 204, and that happens to be falsy. Apps ported from this example to fetch crashed parsing the empty body, and the example's "404 = no entries" handling taught the wrong signal.
  • The poller now returns empty only on 204, and resets the cursor only on a 404 whose subCategory is WebhooksJournalErrorType.JOURNAL_NOT_FOUND (expired offset). Any other 404 now surfaces as an error. An example is the HTML 404 returned once the 2027-03-beta version is retired after 2027-04-23. Previously that would have silently logged "no entries" forever or wiped the cursor on every poll.
  • The README gains an "Empty and Not-Found Responses" table so the signals are explicit for anyone porting the example.

BRAVE Checklist

Backwards compatibility: none broken. Behavior is unchanged for 204, 200 and JOURNAL_NOT_FOUND. The only change is that unexpected 404s are now logged as errors instead of being treated as an empty or expired journal.

Roll(out/back) plan: example app with no deployment. Revert this PR to undo.

Automated testing: new __tests__/poller.test.ts with 6 tests covering a 204 that clears the cursor, a 200 that moves the cursor, a 404 from /latest that is surfaced, a JOURNAL_NOT_FOUND batch 404 that returns null, a non-JOURNAL_NOT_FOUND 404 that is surfaced, and a normal batch. Both 404 tests fail against the previous code. Full suite: 20/20.

Verification plan: ran the app locally against prod. It polled cleanly and a contact update flowed through end to end. Calls to the live API with a fresh app (empty journal) confirmed the shapes: /earliest and /latest give 204 with an empty body, batch/earliest|latest gives 200 {results: []} with numErrors/errors omitted, and an unknown offset on /offset/{o}/next and batch/{o}/next gives 404 with subCategory: WebhooksJournalErrorType.JOURNAL_NOT_FOUND.

Expect dependencies to fail: if the journal API changes these signals, the poller now fails loudly (error log) instead of silently assuming an empty journal.

Zach Probst added 3 commits October 21, 2026 15:26
WebhooksJournal's /earliest and /latest return 204 No Content with an
empty body when an app has no journal entries; they never return 404 for
that. The poller only worked because axios hands back '' for a 204, which
happened to be falsy. Worse, it mapped 404 to "no entries", so a 404 from
a missing route (for example the 2027-03-beta version being retired)
would log "No journal entries available yet" forever instead of an error.
batch/{offset}/next returns a JSON 404 whose subCategory is
WebhooksJournalErrorType.JOURNAL_NOT_FOUND when an offset has expired. A
retired or mistyped API version also returns 404, but as an HTML page.
Treating every 404 as an expired offset would wipe the cursor on each
poll instead of reporting the real problem.

The README now spells out how each endpoint signals empty and not found
(204 vs 200 with empty results vs JOURNAL_NOT_FOUND), because apps
ported from this example to fetch crashed parsing the empty 204 body
that axios had been quietly absorbing.
@zprobs
zprobs marked this pull request as ready for review October 21, 2026 19:52
@zprobs
zprobs merged commit 36fd14c into main Oct 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant