Repository navigation
Conversation
mortondev
force-pushed
the
fix/rest-input-errors
branch
2 times, most recently
from
November 20, 2026 12:02
0a1d053 to
3fbf326
Compare
A body that is not JSON, a malformed id in a cursor or filter, a bad limit, and an unknown category or article in a help center write all reached the database or a bare request.json() and came back as a 500. - readJsonBody reads every /api/v1 body: no body is undefined, a body that is not JSON is a 400. A guard test keeps bare request.json() out. - parseLimit and parseOffset: a limit below 1 or not a whole number is a 400; above the cap it is still capped. - Id cursors and id filters (changelog, posts, incidents, articles, conversations, messages, tickets) are TypeID-checked; a well-formed unknown cursor still pages from the start. - Articles refuse a category that does not exist or was deleted; feedback on an unknown article is a 404. - The services path names a service in its errors; an incident naming a service that never existed says so instead of calling it deleted.
mortondev
force-pushed
the
fix/rest-input-errors
branch
from
November 20, 2026 12:17
3fbf326 to
0d9c8e4
Compare
This branch has not been deployed
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.
What was wrong
Several
/api/v1routes answered 500 when the caller sent bad input:request.json(). Its SyntaxError has no domain code, sohandleDomainErrormapped it to 500.?limit=0or-1on the changelog answered 200 withhasMore: trueand a null cursor.?limit=abcquietly fell back to the default.What changed
All of this lives in shared helpers (
lib/server/domains/api/request.ts), and every v1 route uses them:readJsonBody(request). No body givesundefined, and the route's schema says what is missing. A body that is not JSON is a 400 withRequest body must be valid JSON. All 50 v1 files that read a body now call it. A guard test (json-body-guard.test.ts) fails if a barerequest.json()comes back.parseLimit/parseOffset. A limit below 1 or not a whole number is a 400. A limit above the cap is still capped.parsePaginationParamsusesparseLimit. Applies to changelog, posts, status incidents, help center articles, conversations, messages, tickets, companies and voters.parseCursor. Changelog, posts, incidents, articles, conversations and messages cursors must be a TypeID, or the request is a 400Invalid cursor format. Any well-formed TypeID is accepted, even one of another type, and a cursor that names no row pages from the start. API-R-106 pins that behaviour. Every list hands out row ids as cursors, so real cursors still work. A new test feeds a returned cursor back in.categoryId, conversationsassignedAgentPrincipalId, and ticketsrequesterPrincipalIdandcompanyId. A malformed value is a 400.categoryId.Category not found).recordArticleFeedbackchecks the article exists and throwsARTICLE_NOT_FOUND(404Help center article not found). It only checks that the row exists, so feedback on draft or deleted articles behaves as before./status/servicespath says "service" in its malformed-id and not-found errors. The legacy/status/componentspath still says "component". Both share one handler and pass the noun.An affected service does not exist.Before, it said the service had been deleted. A soft-deleted service keeps the deleted wording.suggestions/:id/accept. The optional body is now checked with a schema. Before, a broken body was silently swallowed.One passing e2e test needs updating: API-R-001 on #1167 (
rest-posts.spec.ts,test/product-e2e-api-rest) pins the old lenient posts limit:limit=-5gives 1 item andlimit=abcgives 20. With this PR both answer 400, as asked for consistently across the list routes. The test's expectations should change to 400.The
moderation/*/rejectroutes still accept an empty body. A body that is present but not JSON is now a 400. Before, it was silently treated as{}.Left to the sibling PRs: users list paging, roadmap posts paging and segments id handling are fixed in
fix/rest-people-errorsandfix/rest-taxonomy-roadmaps-apps. This PR only swapsrequest.json()forreadJsonBodyin their files. Their users route callsparsePaginationParams, so it picks up the stricter limit check.git merge-treeshows no conflicts with either of them, or withfix/rest-post-writes.Quarantined e2e tests this fixes
On #1160 (
test/product-e2e-api-rest-content):On #1165 (
test/product-e2e-api-rest-keys):Tests
All of these failed on main first:
routes/api/v1/__tests__/bad-input.db.test.tsruns the real route handlers against Postgres, with only the key check stubbed. It covers non-JSON bodies, malformed and unknown cursors, id filters, limits, help center references and the services wording.help-center-unknown-references.db.test.tsand new cases instatus.lifecycle.db.test.tscover the service-level checks.request.test.tscovers the helpers (readJsonBody,parseLimit,parseOffset,parseCursor).json-body-guard.test.tsis the source guard.responses.test.ts,articles.test.tsandhelp-center-article-feedback.service.test.tswere updated for the new contract.