Skip to content

BED-31: Upgrade axios from 0.17.1 to latest stable - #117

Open
bhavya-jpg wants to merge 3 commits into
openmrs:masterfrom
bhavya-jpg:master
Open

BED-31: Upgrade axios from 0.17.1 to latest stable#117
bhavya-jpg wants to merge 3 commits into
openmrs:masterfrom
bhavya-jpg:master

Conversation

@bhavya-jpg

@bhavya-jpg bhavya-jpg commented Jul 2, 2026

Copy link
Copy Markdown

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work is based on designs, which are linked or shown either in the Jira ticket or the description below. (N/A for dependency upgrades)
  • My work includes tests or is validated by existing tests.

Summary
This PR upgrades the axios dependency in the bedmanagement-owa module from 0.17.1 to ^1.15.0. The older version carried 20 known security vulnerabilities, including high-severity issues like SSRF, ReDoS, and credential leaks.

Key improvements and fixes:

Bumps axios to ^1.15.0 to resolve all security vulnerabilities.
Fixes brittle .catch() error handlers across 13 components. Axios 1.x exposes a bug in the old implementation where network errors (where .response is undefined) would throw a fatal TypeError. Handlers now safely verify .response exists before attempting to access .data.

Updates webpack.config.js to alias axios to its pre-transpiled browser distribution (axios/dist/axios.js). This resolves build failures caused by the legacy Webpack 3 compiler choking on Axios 1.x's modern ES6 syntax.

Fixes broken Jest imports in admissionLocationWrapper-test.js to use import axios from "axios" rather than axios/index, which was removed in 1.x.

Related Issue
https://openmrs.atlassian.net/browse/BED-31

Other
Validated with yarn audit which confirms zero vulnerabilities remaining in the Axios dependency tree.
Verified locally that all 56 frontend Jest tests and 46 backend Maven tests pass successfully without any regressions.

@bhavya-jpg

Copy link
Copy Markdown
Author

@jayasanka-sack hi jay ,can I get a review on this please

});

const error = errorResponse.response.data ? errorResponse.response.data.error : errorResponse;
const error = errorResponse.response && errorResponse.response.data ? errorResponse.response.data.error : errorResponse;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this catch block is exactly what the PR is hardening, a one-word fix worth folding in while you're here: the this.setState at the top of this handler (line 120) throws before this line ever runs. The callback is a plain function, so this is undefined in the transpiled strict-mode code. Net effect: when a save fails, the user gets no error toast and the form is left stuck with disableSubmit: true. Changing it to self.setState, as every other handler in this sweep already does, makes the guard you added here actually reachable. It predates your change and this is the only file with the problem (I checked the others), so I'd also be fine with it as a quick follow-up if you'd rather keep this PR mechanical.

import AdmissionLocationWrapper from "components/admissionLocation/admissionLocationWrapper.js";
import MockAdapter from "axios-mock-adapter";
import axios from "axios/index";
import axios from "axios";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, and I wouldn't hold the PR for it: none of the suites exercise an error path, so the handler guards (the main behavioral fix here) have no test that fails on 0.17.1 and passes after the upgrade. axios-mock-adapter resolves to 1.22.0 in the lockfile, which supports .networkError() for exactly this failure shape. One case along the lines of

mock.onGet('https://192.168.33.10/openmrs/ws/rest/v1/bedtype').networkError();

plus an assertion that the wrapper notifies instead of throwing would pin the new behavior down, so a future change can't quietly reintroduce the crash.

@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

@bhavya-jpg

Copy link
Copy Markdown
Author

Hey @dkayiwa Thanks so much for the detailed review and for catching that this.setState bug!

I completely agree that it makes sense to fix it while we're in here hardening the error handling. I've updated the catch block in addEditAdmissionLocation.js to correctly use self.setState, so if a request fails, the component will actually recover and display the error toast as intended rather than silently crashing. I double-checked the file and this was indeed the only spot missing the const self = this; pattern.

@bhavya-jpg

Copy link
Copy Markdown
Author

I also went ahead and took your suggestion to add a test case! I added a new test in admissionLocationWrapper-test.js using mock.onGet(...).networkError(). I verified that it properly fails if the this.setState bug is present, and now passes flawlessly with the fix, proving that the notify() behavior is successfully pinned down against any future regressions.

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.

2 participants