API: a request the client got wrong is a 400 (or 413), never a 500 with a stack trace — bad or non-object JSON, an array as the state document, null workout entries, a rest timer without seconds (QA C17, C19, C20, C16)
readBody rejects with a typed HttpError for unparseable text and for a JSON null, string,
number or array; the catch-all answers it with its status and does not log it — three of
these routes are reachable without a session, and a stack trace per malformed body let
anyone fill the container log. String() on a caller-supplied field went through the same
door ({"code":{"toString":1}} is valid JSON) and is replaced by a text() helper.
PUT /api/data refuses an array state (typeof 'object', but _rev on it is dropped by
JSON.stringify, so the file read back as rev 0 while the response claimed rev N+1) and
drops null and non-object entries from workouts/routines instead of refusing them: such an
entry carries nothing worth keeping, while a 400 would strand a client whose own copy is
already malformed in a re-send loop. Every server-side reader of the document (reminder
tick, admin drill-down) dereferences the entries.
POST /api/push/rest-timer validates seconds before clamping — the clamp ran first, turned
any missing or unusable value into a 1-second push and made the documented 400 unreachable.
A body over 5 MiB is a 413 the client actually gets to read: the remainder of the upload is
drained instead of the socket destroyed under it (which sent a reset that a node client hit
before parsing the answer — the QA proxy reported 502 on 3 of 4 attempts, 5 of 5 read the
413 afterwards); past twice the cap the upload is cut off. openapi.yaml documents the
400/413 bodies and the rest-timer 400.
This commit is contained in:
1 parent
83b2a140d6
commit
f94f8ca320
3 files changed
+263
-21
No files matched your search
+17
-7
@@ -50,7 +50,11 @@ info:
|
||||
- Errors are always `{"error": "<human-readable message>"}`.
|
||||
- Unknown method+path pairs return `404 {"error":"not found"}`; an unhandled
|
||||
exception returns `500 {"error":"server error"}`.
|
||||
- Request bodies are parsed as JSON regardless of Content-Type; max 5 MiB.
|
||||
- Request bodies are parsed as JSON regardless of Content-Type. A body that does
|
||||
not parse, or parses to anything but an object (`null`, a string, an array), is
|
||||
`400 {"error":"invalid json"}` on every route that reads one; an empty body counts
|
||||
as `{}`. A body over 5 MiB is `413 {"error":"body too large"}`; the rest of the
|
||||
upload is discarded so the answer reaches the client.
|
||||
- CORS: the request's `Origin` is reflected in `Access-Control-Allow-Origin`
|
||||
**without** `Allow-Credentials` — cross-origin callers can only ever
|
||||
authenticate with a Bearer token, never with the cookie.
|
||||
@@ -556,8 +560,10 @@ paths:
|
||||
- type: 'null'
|
||||
'400':
|
||||
description: >-
|
||||
`state` missing or not an object, or `workouts`/`routines` set to anything
|
||||
other than an array or null.
|
||||
`state` missing or not an object, `state` an array, or `workouts`/`routines`
|
||||
set to anything other than an array or null. Entries inside those two arrays
|
||||
that are not objects (`null`, numbers, nested arrays) are dropped before the
|
||||
write rather than refused, so a client with a damaged copy still syncs.
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/Error' }
|
||||
@@ -725,7 +731,8 @@ paths:
|
||||
operationId: pushRestTimer
|
||||
summary: Schedule a server-side rest-timer push
|
||||
description: |
|
||||
Schedules one push after `seconds` (clamped to 1–3600). One pending timer per
|
||||
Schedules one push after `seconds` (a number or numeric string ≥ 1, clamped to
|
||||
3600). One pending timer per
|
||||
device — `deviceId`, the same token the subscription was registered with; a
|
||||
new call from the same device replaces it, and the push goes only to that
|
||||
device's subscriptions. Without a `deviceId` there is one timer per account
|
||||
@@ -733,9 +740,6 @@ paths:
|
||||
on rest start/extend and cancels on skip or on-screen completion — the push
|
||||
only actually fires when the tab was backgrounded/suspended and never got to
|
||||
cancel it. Timers live in memory: an API restart drops them.
|
||||
|
||||
Note: the documented `400 seconds required` exists in the code but is
|
||||
unreachable — the clamp turns any missing/invalid value into 1.
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
@@ -759,6 +763,12 @@ paths:
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/Ok' }
|
||||
'400':
|
||||
description: '`seconds` missing, not numeric, or below 1. Nothing is scheduled.'
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: '#/components/schemas/Error' }
|
||||
example: { error: "seconds required" }
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
|
||||
/api/push/rest-timer/cancel:
|
||||
|
||||
Reference in new issue
Block a user