Skip to content

Commit

Permalink
Merge pull request #9 from riddhesh-mahajan/features/code_executor
Browse files Browse the repository at this point in the history
catch error for code/run api call
  • Loading branch information
riddhesh-mahajan authored Oct 31, 2023
2 parents a16a120 + 5459758 commit 28f320b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions apps/backend/app/api/code/run/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,26 @@ export async function POST(request: Request) {
});
}

const codeExecutionResponse = await axios.post(
`${process.env.CODE_EXECUTOR_URL}/api/code/run`,
{
code,
testCases: targetQuestion.testCases,
answer: targetQuestion.answer,
}
);
let codeExecutionResponse = null;

let codeOutput: any[] = codeExecutionResponse.data.payload;
try {
codeExecutionResponse = await axios.post(
`${process.env.CODE_EXECUTOR_URL}/api/code/run`,
{
code,
testCases: targetQuestion.testCases,
answer: targetQuestion.answer,
}
);
} catch (err: any) {
return createResponse({
message: messages.ERROR,
payload: { error: err?.response?.data?.payload },
status: statuscodes.BAD_REQUEST,
});
}

let codeOutput: any[] = codeExecutionResponse?.data?.payload;

// Record run
await prisma.run.create({
Expand Down

0 comments on commit 28f320b

Please sign in to comment.