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

263
Views
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
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!