S1: unify error responses + id parsing (responses.py) across notes.py
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 6s
CI & Build / Python tests (push) Successful in 9s
CI & Build / Build & push image (push) Successful in 33s

M9 section S1, commit 2. Add src/thoughtsync/responses.py — the app's single
JSON-error shape and the two guards that pair with it:
  - json_error(message, status): the one ({"error": ...}, code) builder
  - not_found(): the standard 404, by far the most common note-route error
  - parse_uuid(raw): parse a path/body id, None on malformed → pair with not_found()

notes.py adopts them everywhere: ~25 hand-built `jsonify({"error":"not found"}),404`
collapse to not_found(); ~20 other error returns to json_error(...); ~13 repeated
`try: uuid.UUID(x) except: ...` blocks to parse_uuid(). Behavior-preserving — same
bodies and status codes, one definition. jsonify stays for the success responses.

Other blueprints (auth, labels, saved_filters, sync, settings_api) adopt the same
helpers in their own M9 sections.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
This commit is contained in:
2026-07-23 19:29:46 -04:00
co-authored by Claude Opus 4.8
parent 2abed7132c
commit 6abc82c783
2 changed files with 118 additions and 99 deletions
+28
View File
@@ -0,0 +1,28 @@
from __future__ import annotations
import uuid
from quart import jsonify
# The app's single JSON error shape + the two guards that pair with it, so every
# blueprint returns errors and parses path ids the same way instead of hand-building
# `jsonify({"error": ...}), code` and try/except uuid blocks at ~35 call sites.
def json_error(message: str, status: int):
"""A JSON error body + status: ({"error": message}, status)."""
return jsonify({"error": message}), status
def not_found():
"""404 with the standard body — by far the most common error in the note routes."""
return json_error("not found", 404)
def parse_uuid(raw: object) -> uuid.UUID | None:
"""Parse a path/body UUID, returning None on anything malformed. Pair with
not_found() for the ubiquitous 'bad id in the URL → 404' guard."""
try:
return uuid.UUID(str(raw))
except (ValueError, TypeError):
return None