Skip to content

Commit

Permalink
added try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoluizpoli committed Oct 11, 2023
1 parent 90401c6 commit db73357
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/server/controller/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,33 @@ const get = async (req: Request) => {
},
);
}
const output = await todoRepository.get({
limit,
page,
});
try {
const output = await todoRepository.get({
limit,
page,
});

return new NextResponse(
JSON.stringify({
total: output.total,
pages: output.pages,
todos: output.todos,
}),
{ status: 200 },
);
return new NextResponse(
JSON.stringify({
total: output.total,
pages: output.pages,
todos: output.todos,
}),
{ status: 200 },
);
} catch (error) {
return new NextResponse(
JSON.stringify({
error: {
message: 'failed to get todos',
details: error,
},
}),
{
status: 400,
},
);
}
};

const toggleDone = async (req: NextApiRequest, res: NextApiResponse) => {
Expand Down

0 comments on commit db73357

Please sign in to comment.