Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
How can I pass a variable that consists of options to `client.request` undici?

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.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!