Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda