Skip to content

Commit c741c04

Browse files
Copilotaviadhahami
andcommitted
Address code review: add URL error handling and comment for validateStatus
Co-authored-by: aviadhahami <7353632+aviadhahami@users.noreply.github.com>
1 parent 21b3915 commit c741c04

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

src/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ module.exports = (config = {}) => {
4848
: undefined;
4949

5050
const instance = axios.create({
51+
// Accept all HTTP status codes (equivalent to request's simple: false)
52+
// so that vault response handling logic can process non-2xx responses.
5153
validateStatus: () => true,
5254
...(httpsAgent ? { httpsAgent } : {}),
5355
...(rpDefaults.timeout ? { timeout: rpDefaults.timeout } : {}),
@@ -64,13 +66,21 @@ module.exports = (config = {}) => {
6466
axiosOptions.data = options.json;
6567
}
6668

67-
return instance(axiosOptions).then((response) => ({
68-
statusCode: response.status,
69-
body: response.data,
70-
request: {
71-
path: new URL(options.uri).pathname,
72-
},
73-
}));
69+
return instance(axiosOptions).then((response) => {
70+
let requestPath;
71+
try {
72+
requestPath = new URL(options.uri).pathname;
73+
} catch (_e) {
74+
requestPath = options.uri;
75+
}
76+
return {
77+
statusCode: response.status,
78+
body: response.data,
79+
request: {
80+
path: requestPath,
81+
},
82+
};
83+
});
7484
};
7585
})();
7686
const client = {};

0 commit comments

Comments
 (0)