I am making a bunch of post requests to my API that will return some html/invoices, there are two scenerios where all the responses seem to be correct.
However, when I post a high amount of requests with large bodies(e.g each post request contains an array of customer orders that is > 150), some of the promises return as null values.
Larger amount of requests results Small amount of requests result
With the returned data I want to generate a zipFolder full of invoices, but because some promises return null, some invoices are missing.
getSummaryInvoiceDetails() {
this.zip = new JSZip();
this.summary.forEach(element => {
if (element.ShopId <= 50) {
this.shopId = element.ShopId;
this.invoiceData = mapInvoiceData(element);
this.getOrderInvoiceDetails(element.ShopId);
this.generateInvoice();
}
});
this.zipInvoices();
},
async getOrderInvoiceDetails(shopId) {
this.weeklyDetails.forEach(element => {
if (element.shopId === shopId) {
const obj = {};
obj.OrderRef = element.ref;
obj.Contact = element.name;
obj.OrderTotal = element.ordeR_TOTAL;
obj.DeliveryCharge = element.deliverY_CHARGE;
obj.PaymentMethod = element.payment;
obj.OrderTime = element.ordeR_TIME;
this.invoiceData.Orders.push(obj);
}
});
},
async zipInvoices() {
// Zip files when all invoices generated/promises resolved
const res = await Promise.all(this.promiseArray);
console.log(res);
res.forEach(element => {
let shopName = '';
try {
shopName = this.invoiceNameArray[this.x];
const blob = new Blob([element.data], { type: 'text/plain;charset=utf-8' });
this.zip.file(`${shopName}.html`, blob);
} catch (err) {
console.log(shopName);
}
this.x += 1;
});
this.zip.generateAsync({ type: 'blob' })
.then(content => {
FileSaver.saveAs(content, 'Invoices.zip');
});
},
async generateInvoice() {
const result = this.getInvoice(this.invoiceData);
this.invoiceNameArray.push(this.invoiceData.ShopName);
this.promiseArray.push(result);
},
This is the type of data in body of the post request
My project is in Vue.js and the backend is dotnet core