more robust promise.all

This commit is contained in:
Nour Alharithi
2024-02-26 12:28:53 -08:00
parent 93d6ca22bc
commit 1d43893452

View File

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