Skip to content

fix(auth): read axios error status from e.response, not e.status - #52

Open
SafraNako wants to merge 1 commit into
energywebfoundation:masterfrom
SafraNako:fix/axios-error-status
Open

SafraNako wants to merge 1 commit into
energywebfoundation:masterfrom
SafraNako:fix/axios-error-status

Conversation

@SafraNako

Copy link
Copy Markdown

Fixes #51

What

getWorkerRegistrationStatus() in src/auth/registry.ts branches on e.status,
but axios@1.7.9 (pinned) puts the HTTP status on e.response.status — the
top-level e.status alias was only added in axios 1.8.0. So e.status === 404
is always false and both 404 branches are unreachable:

  • a not-yet-registered worker's 404 WorkerNotFoundException returns ERROR
    instead of NOT_EXISTS, so registerWorker() never reaches
    storeWorkerInRegistry() and loops forever under promiseRetry({ forever: true });
  • the empty-body 404 "invalid path" branch is also dead.

Change

  • Read status / data from e.response?.… in the getWorkerRegistrationStatus
    .catch, so the NOT_EXISTS and "invalid path" branches work again.
  • logger.error(e.data)logger.error(data) (was always logging undefined).
  • Guard the e.response.data reads in the .catch handlers of
    storeWorkerInRegistry and obtainTokenFromAuthServer (src/auth/login.ts) —
    on a network-level error e.response is undefined and e.response.data
    throws a TypeError from inside the catch, masking the real error.

Matches the existing e.response?.status pattern in src/util/base-urls.ts.

Notes

Behaviour-only fix, 2 files. The repo has no test suite (npm test is a stub), so
this is covered by inspection. Verified prettier --check passes on both files.

🤖 Generated with Claude Code

axios <1.8 does not set a top-level `status` on the error object — the HTTP
status lives at `e.response.status`. `getWorkerRegistrationStatus` gated its
404 handling on `e.status === 404`, which is always `undefined` with the pinned
`axios@1.7.9`, so both branches were dead:

- a not-yet-registered worker (404 `WorkerNotFoundException`) was classified as
  `ERROR` instead of `NOT_EXISTS`, so `registerWorker` never calls
  `storeWorkerInRegistry` and retries forever (`{ forever: true }`);
- the empty-body 404 "invalid path" branch was also unreachable.

Also guard the `e.response.data` reads in the `.catch` handlers of
`getWorkerRegistrationStatus`, `storeWorkerInRegistry` and `obtainTokenFromAuthServer`:
on a network-level error `e.response` is undefined, so `e.response.data` throws a
`TypeError` from inside the catch and masks the original failure. Matches the
existing `e.response?.status` usage in util/base-urls.ts.

Co-Authored-By: Claude Sonnet 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.

auth: getWorkerRegistrationStatus 404 handling is dead code (e.status is undefined on axios 1.7.9)

1 participant