I have a function that uses undici.Client, I am trying to use client.request with some options that are stored in a variable to make the call but I get the following error:
InvalidArgumentError: invalid opts
My function is as follows:
module.exports.request = async (clientName, method, path, options) => {
const client = await getClient(clientName);
const sym = Object.getOwnPropertySymbols(client)
.find((s) => {
return String(s) === 'Symbol(url)';
});
log.info('calling %s from %s', path, client.url);
// eslint-disable-next-line security/detect-object-injection
let preparedOptions = await prepareOptions(clientName, method, client[sym].origin + path, options);
return client.request(path, preparedOptions)
.catch(async (err) => {
if (!isNil(err.response) && (err.response.statusCode === 401 || err.response.statusCode === 403)) {
// eslint-disable-next-line security/detect-object-injection
preparedOptions = await prepareOptions(clientName, method, client[sym].origin + path, options, true);
return client.request(path, preparedOptions);
}
throw err;
});
};
The console.log(preparedOptions) looks like:
{
method: 'GET'
}
This looks like a reasonable output to me.
How can I overcome this error?
I have created a gist if further info is required on other functions used
PS: The current function will not match on gist as I am updating it but if more info on prepareOptions or getClient is reqiured, you can refer to the gist.