more robust promise.all

This commit is contained in:
Nour Alharithi
2024-02-26 12:29:39 -08:00
parent b8137b6c59
commit 2701b6bb26

View File

@@ -1000,6 +1000,8 @@ const main = async (): Promise<void> => {
return;
}
let hasError = false;
let errorMessage = '';
const l2s = await Promise.all(
normedParams.map(async (normedParam) => {
const { normedMarketType, normedMarketIndex, error } =
@@ -1011,7 +1013,8 @@ const main = async (): Promise<void> => {
normedParam['marketName'] as string
);
if (error) {
res.status(400).send(`Bad Request: ${error}`);
hasError = true;
errorMessage = `Bad Request: ${error}`;
return;
}
@@ -1136,6 +1139,11 @@ const main = async (): Promise<void> => {
})
);
if (hasError) {
res.status(400).send(errorMessage);
return;
}
res.writeHead(200);
res.end(JSON.stringify({ l2s }));
} catch (err) {