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

265
Visualizações
Typescript: Updating generic request function to grab response data - MX / AxiosResponse

I am updating my firebase functions to grab data from MX's platform API. I used to grab data via MX's atrium API. Given I am now grabbing an AxiosResponse type, I need to update the generic function used request/process the data. In addition, I do not know typescript/javascript well and am struggling with the correct formatting. I really appreciate the help!

Error: 'Argument of type 'AxiosResponse' is not assignable to parameter of type '{ response: AxiosResponse<any, any>; body: unknown; }'. Type 'AxiosResponse' is missing the following properties from type '{ response: AxiosResponse<any, any>; body: unknown; }': response, body '

This is my attempt to update the generic request function but is causing the error:

const getDataFromMXResponse = <T>({
  response,
  body,
}: {
  response: AxiosResponse;
  body: T;
}): T => {
  const { statusCode = 400 } = response.status;
  if (200 <= statusCode && statusCode <= 299) {
    body = response.data;
    return body;
  } else {
    throw new Error(response.statusText || "");
  }
};

This line of code is calling the actual function:

const listAccountsResponse = await this.mx.listUserAccounts(
 mxUserGuid,
 1,
 100
);
const accounts = getDataFromMXResponse(listAccountsResponse).accounts || [];

This is the original generic request function:

const getDataFromMXResponse = <T>({
  response,
  body,
}: {
  response: IncomingMessage;
  body: T;
}): T => {
  const { statusCode = 400 } = response;
  if (200 <= statusCode && statusCode <= 299) {
    return body;
  } else {
    throw new Error(response.statusMessage || "");
  }
};
about 4 years ago · Juan Pablo Isaza
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