diff --git a/src/index.ts b/src/index.ts index e05e454..764b6e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1000,6 +1000,8 @@ const main = async (): Promise => { 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 => { 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 => { }) ); + if (hasError) { + res.status(400).send(errorMessage); + return; + } + res.writeHead(200); res.end(JSON.stringify({ l2s })); } catch (err) {