Skip to content

Fix npm run lint and API requests that get no response - #613

Open
eabdullin1 wants to merge 2 commits into
AlmaLinux:masterfrom
eabdullin1:fix-lint-and-api-errors
Open

eabdullin1 wants to merge 2 commits into
AlmaLinux:masterfrom
eabdullin1:fix-lint-and-api-errors

Conversation

@eabdullin1

Copy link
Copy Markdown
Contributor

Problem

  • npm run lint fails on master with Invalid option '--ext': Dependabot bumped ESLint to 9, which reads only flat configs by default, while the project has .eslintrc.js. ESLint 9 also needs Node.js 18.18+, and the Docker image used by CI and docker-compose runs Node.js 16.20.
  • The axios response interceptor in src/boot/api.js reads error.response.status of every failed request. A network error, a timeout or a cancelled request has no response, so the interceptor throws a TypeError instead of rejecting with the axios error, and the user sees nothing.

Changes

  • ESLint 8.57 instead of 9, rules and plugins unchanged. npm run lint passes (68 files, no errors or warnings) without ESLINT_USE_FLAT_CONFIG. Dependabot skips ESLint major updates, so it doesn't bring 9 back before the image moves to a newer Node.js.

  • Interceptor: the handler moved to src/apiErrors.js.

    • network error: "Cannot reach the server…";
    • timeout: "The server did not answer in time…";
    • request cancelled on purpose or aborted by the browser: no notification;
    • anything else without a response: "The request failed: ".

    Notifications look like the other ones. The promise always rejects with the original error, 401 and 403 work as before. Prettier reformatted src/boot/api.js.

  • Unit tests on the built-in Node.js test runner (npm test, no new packages): a small loader hook loads src/ as ES modules, so the tests run on Node.js 16 as well. 10 tests run real axios with a stubbed adapter; 4 of them fail with the old TypeError if the unchecked error.response.status is put back.

Testing

Where lint test build
Docker image of the repo, Node.js 16.20.2 0 0 0
Local, Node.js 25.2.1 0 0 0

Not changed

Many .catch handlers in src/ read error.response.* themselves (e.g. getFromApi in src/utils.js). On a network error the user now gets a clear notification, but those handlers still throw a TypeError in the console. That is left for a separate change.

🤖 Generated with Claude Code

Dependabot bumped ESLint to 9, which reads only flat configs by
default, so "npm run lint" failed with "Invalid option '--ext'" on the
.eslintrc.js of the project. ESLint 9 also needs Node.js 18.18+, while
the Docker image used by CI and docker-compose runs Node.js 16.20.
Go back to ESLint 8.57, which supports both, and keep the rules and
plugins as they are. Tell Dependabot to skip ESLint major updates.
The response interceptor read error.response.status of every failed
request, so a network error, a timeout or a cancelled request, which
have no response, threw a TypeError inside the interceptor instead of
rejecting with the axios error, and the user saw nothing.

Move the handler to src/apiErrors.js and tell the user when the server
cannot be reached or does not answer in time; stay silent for requests
cancelled on purpose or aborted by the browser. The handler always
rejects with the original error, and 401 and 403 work as before.

Cover it with unit tests on the built-in Node.js test runner: npm test
loads src/ as ES modules with a small loader hook, so it runs on the
Node.js 16 of the Docker image as well.
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.

1 participant