Skip to content

fix: implement resilient POST client for replay job submission#319

Merged
codeZe-us merged 1 commit into
Toolbox-Lab:mainfrom
MorsH14:fix/313-resilient-replay-submitter
Jul 16, 2026
Merged

fix: implement resilient POST client for replay job submission#319
codeZe-us merged 1 commit into
Toolbox-Lab:mainfrom
MorsH14:fix/313-resilient-replay-submitter

Conversation

@MorsH14

@MorsH14 MorsH14 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Implements the examples/api-clients/mock-replay-submitter/index.js script, previously a one-line stub, as a resilient HTTP client wrapper around native fetch.
  • Sets Content-Type: application/json and Accept: application/json headers on the POST to http://localhost:3001/api/replay (overridable via API_URL env var, consistent with the sibling websocket-client example).
  • Catches network-level failures (DNS errors, connection refused, server downtime) so they surface as a clear message instead of an unhandled Promise rejection that crashes the process.
  • Checks Response.ok before trusting the body, safely parses Response.json(), and extracts jobId, throwing a descriptive error for non-2xx responses (including 500) or a response missing jobId.

Test plan

Verified locally against apps/server (pnpm --filter grat-server dev):

  • Server down → clean "could not reach grat-server" message, exit code 1, no unhandled rejection.
  • No tx-hash argument → usage message, exit code 1.
  • Server up, proper headers sent → no 415 (confirmed the request negotiates correctly).
  • Simulated 500 response → descriptive HTTP 500 ... : temporary test failure error, exit code 1.
  • Simulated success with no jobId in body (current state of POST /api/replay, which only returns { status: "queued" }) → descriptive "response did not include a jobId" error, exit code 1.

Note: apps/server's POST /api/replay handler currently returns { status: "queued" } with no jobId field at all (it's a scaffold/stub, out of scope for this issue per the "Files location" in #313). Once that route is implemented to actually return a jobId, this client will pick it up correctly with no changes needed — confirmed by testing against a temporarily-patched local route.

Fixes #313

🤖 Generated with Claude Code

Replace the mock-replay-submitter stub with a real HTTP client wrapper
around native fetch. Sets Content-Type/Accept: application/json to
satisfy Fastify's payload handling, checks Response.ok before trusting
the body, safely parses the JSON reply, and extracts jobId - throwing
descriptive errors for non-2xx responses or a missing jobId instead of
letting network failures (DNS, connection refused, downtime) surface
as unhandled Promise rejections that crash the process.

Fixes Toolbox-Lab#313

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codeZe-us
codeZe-us self-requested a review July 16, 2026 22:19
@codeZe-us
codeZe-us merged commit b01406a into Toolbox-Lab:main Jul 16, 2026
2 checks 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.

Task 17: Client Needs a Resilient POST Request Layer to Submit Replay Jobs

2 participants