Sync reading position from Moon Reader app to Bookhive atproto records
atproto bookhive ereader moonreader
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

add better logging

+16 -2
+16 -2
src/waggle/atproto/bookhive.py
··· 347 347 return value, True 348 348 349 349 350 + def _raise_with_body(resp: httpx.Response, value: dict, op: str) -> None: 351 + """raise_for_status, but log the PDS error body + payload first. 352 + 353 + Why: the PDS returns 400 with a JSON body that names which lexicon field 354 + failed validation; httpx's default exception swallows it. 355 + """ 356 + if resp.status_code >= 400: 357 + log.error( 358 + "PDS %s rejected (%d): %s\nrecord we sent: %s", 359 + op, resp.status_code, resp.text, value, 360 + ) 361 + resp.raise_for_status() 362 + 363 + 350 364 async def put_record(client: ATProtoClient, rkey: str, value: dict) -> None: 351 365 did = await client.did() 352 366 resp = await client.request( ··· 358 372 "record": value, 359 373 }, 360 374 ) 361 - resp.raise_for_status() 375 + _raise_with_body(resp, value, f"putRecord rkey={rkey}") 362 376 invalidate_cache(did) 363 377 364 378 ··· 368 382 "POST", "com.atproto.repo.createRecord", 369 383 json={"repo": did, "collection": BOOKHIVE_COLLECTION, "record": value}, 370 384 ) 371 - resp.raise_for_status() 385 + _raise_with_body(resp, value, "createRecord") 372 386 invalidate_cache(did) 373 387 uri = resp.json().get("uri", "") 374 388 return uri.rsplit("/", 1)[-1]