mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 14:57:28 +00:00
Return 400 for invalid task JSON (#19)
This commit is contained in:
parent
301b4ed535
commit
aa7eb32c36
2 changed files with 22 additions and 1 deletions
|
|
@ -104,7 +104,14 @@ async function route(request: IncomingMessage, response: ServerResponse) {
|
|||
}
|
||||
|
||||
if (request.method === "POST" && url.pathname === "/api/tasks") {
|
||||
const body = await readJson(request);
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await readJson(request);
|
||||
} catch {
|
||||
json(response, 400, { error: "Invalid JSON body" });
|
||||
return;
|
||||
}
|
||||
|
||||
const result = validate("task", body);
|
||||
if (!result.ok) {
|
||||
json(response, 422, { errors: result.errors });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue