mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-08 03:08:21 +00:00
handle errors properly
This commit is contained in:
parent
76d435de89
commit
626ca898e4
1 changed files with 15 additions and 1 deletions
|
|
@ -16,7 +16,21 @@ export async function POST(req: NextRequest) {
|
|||
return new Response("Missing BACKEND_SECURITY_KEY", { status: 500 });
|
||||
}
|
||||
|
||||
const body = await req.json();
|
||||
let body;
|
||||
|
||||
try {
|
||||
body = await req.json();
|
||||
} catch (e) {
|
||||
const error = (e as Error).message;
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
message: "A JSON was not sent to the API. " + error,
|
||||
}),
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const validated = addFromAPIType.safeParse(body);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue