I have a function that calls a 3rd party API (via the function checkPosition
)which sometimes fails (this is after a 30 sec timeout). I have the function around a Try – Catch, but the 504 crashes the program.
<code>try {
// Check if position is still open
if (!(await checkPosition(client, item.dealID))) {
// If position has been manually closed
console.log(`Position with period ${key} has been manually removed.`);
continue;
}
await closePosition(client, item.epic, item.purchaseAmount, direction);
}
catch (err)
{
console.error(err);
res.redirect("/");
}
</code>
<code>try {
// Check if position is still open
if (!(await checkPosition(client, item.dealID))) {
// If position has been manually closed
console.log(`Position with period ${key} has been manually removed.`);
continue;
}
await closePosition(client, item.epic, item.purchaseAmount, direction);
}
catch (err)
{
console.error(err);
res.redirect("/");
}
</code>
try {
// Check if position is still open
if (!(await checkPosition(client, item.dealID))) {
// If position has been manually closed
console.log(`Position with period ${key} has been manually removed.`);
continue;
}
await closePosition(client, item.epic, item.purchaseAmount, direction);
}
catch (err)
{
console.error(err);
res.redirect("/");
}
I tried to catch the 504 but this is not working for me.
New contributor
Christopher Chapman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1