Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda