How Vercel.com handles api calles? It seems that some 3rd party call is responded more than 1 minutes later, or it is not even responded.
3rd party claims with timestams, that they responded in 1 second.
Who is right who is wrong? Can it be that queues are used in Vercel and they postpone the handling of an async process?
It is possible that some variable will loose value meantime?
async function sendInvoice(
db: Db,
payment: Payment,
vegszamla: boolean,
xml: string,
paymentAndInvoiceRecipientId?: string
): Promise<void> {
await db.collection('logs').insertOne({
service: 'sendInvoice',
createdAt: new Date(),
severity: 'log',
message: 'Sending invoice starting',
xml,
})
const timestamp = new Date()
let d = {
createdAt: timestamp,
}
if (paymentAndInvoiceRecipientId) {
d['paymentAndInvoiceRecipientId'] = paymentAndInvoiceRecipientId
}
if (vegszamla) {
db.collection('payments').updateOne(
{ _id: payment._id },
{
$push: {
finalInvoices: d,
},
}
)
} else {
db.collection('payments').updateOne(
{ _id: payment._id },
{
$push: {
invoices: d,
},
}
)
}
const blob = new Blob([xml], { type: 'text/plain' })
const formData = new FormData()
formData.append('action-xmlagentxmlfile', blob, 'xmlfile.xml')
const response = await fetch(`https://www.szamlazz.hu/szamla/`, {
method: 'POST',
body: formData,
})
const text = await response.text()
await db.collection('logs').insertOne({
service: 'prepareAndSendInvoice',
createdAt: new Date(),
severity: 'log',
message: 'Sending invoice response received',
status: response.status,
})
if (response.status === 200 && !response.headers.has('szlahu_error')) {
const invoiceId = response.headers.get('szlahu_szamlaszam')
await db.collection('logs').insertOne({
service: 'prepareAndSendInvoice',
createdAt: new Date(),
severity: 'log',
message: 'Invoice ID read',
invoiceId,
paymentId: payment._id,
timestamp,
})
if (!invoiceId) {
await db.collection('logs').insertOne({
service: 'sendInvoice',
createdAt: new Date(),
severity: 'error',
message: 'No tetelek created',
})
return Promise.reject(new Error('No invoiceId returned by provider'))
}
if (vegszamla) {
db.collection('payments').updateOne(
{ _id: payment._id, 'finalInvoices.createdAt': timestamp },
{ $set: { 'finalInvoices.$.id': invoiceId } }
)
} else {
db.collection('payments').updateOne(
{ _id: payment._id, 'invoices.createdAt': timestamp },
{ $set: { 'invoices.$.id': invoiceId } }
)
}
await db.collection('logs').insertOne({
service: 'prepareAndSendInvoice',
createdAt: new Date(),
severity: 'log',
message: 'Sending invoice finished',
})
} else {
await db.collection('logs').insertOne({
service: 'sendInvoice',
createdAt: new Date(),
severity: 'error',
responseText: text,
responseStatus: response.status,
responseHeaders: response.headers,
xml,
})
}
}