Skip to content

fix(amp admin api): keep http client errors typed, map 401/403 to Unauthorized/Forbidden - #30

Draft
benface wants to merge 1 commit into
mainfrom
benface/admin-api-typed-errors
Draft

benface wants to merge 1 commit into
mainfrom
benface/admin-api-typed-errors

Conversation

@benface

@benface benface commented Nov 2, 2026

Copy link
Copy Markdown

Admin API methods turned every HttpClientError into a defect, so failures their own error type declares killed the fiber and catchTag never ran. They now stay typed failures, and 401 and 403 become Unauthorized and Forbidden on every method, whatever the body.

  • A connection error or an undeclared status (like a 502) is now a typed HttpClientError instead of a defect.
  • A 401 or 403 is now Unauthorized or Forbidden on every method, as HttpError already promised, including with Amp's {"error_code": …} body or an empty one.

You might prefer:

  • Declaring 401 and 403 on each endpoint in api.ts, with schemas that accept Amp's error bodies, instead of mapping them by status in the service.
  • Typing SchemaError too. It's still a defect, but it isn't in any method's error type, so I left it.
  • Keeping Amp's error_message. Unauthorized and Forbidden have no fields, so it's dropped.

Checks:

  • pnpm lint, pnpm check:tsgo, pnpm test (237 passed, 4 new) and pnpm circular pass.
  • With the real FetchHttpClient, a closed port and a local server answering 401, 403, 404 and 502 all fail with the expected typed error instead of dying.
  • Against ampd v0.0.42, getDatasets, getProviders, getWorkers and getJobs still decode, and getJobById and stopJob still fail with JobNotFoundError.

Fixes #29

🤖 Generated with Claude Code

…uthorized/Forbidden

Every AdminApi method turned HttpClientError into a defect, so failures its
type declares (connection errors, undeclared statuses) killed the fiber and
catchTag("HttpClientError") never ran. 401 and 403 responses now become
Unauthorized and Forbidden on every method whatever their body, as HttpError
promises. Schema errors stay defects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Admin API failures are defects, not errors

1 participant