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 || "");
}
};