fix: return support action errors

This commit is contained in:
vimtor
2026-06-23 11:26:26 +02:00
parent d54be42a69
commit 3e966f6e16
3 changed files with 20 additions and 8 deletions
@@ -15,6 +15,12 @@ export async function POST(event: APIEvent) {
}
const body = Body.safeParse(await event.request.json().catch(() => undefined))
if (!body.success) return Response.json({ error: "Invalid request" }, { status: 400 })
return Response.json(await Referral.create(body.data))
if (!body.success) {
return Response.json({ error: "Invalid request", issues: body.error.issues }, { status: 400 })
}
return Referral.create(body.data)
.then((result) => Response.json(result))
.catch((error) =>
Response.json({ error: error instanceof Error ? error.message : String(error) }, { status: 400 }),
)
}
@@ -12,7 +12,12 @@ export async function DELETE(event: APIEvent) {
}
const body = Body.safeParse(await event.request.json().catch(() => undefined))
if (!body.success) return Response.json({ error: "Invalid request" }, { status: 400 })
await Account.remove(body.data.accountID)
return Response.json({})
if (!body.success) {
return Response.json({ error: "Invalid request", issues: body.error.issues }, { status: 400 })
}
return Account.remove(body.data.accountID)
.then(() => Response.json({}))
.catch((error) =>
Response.json({ error: error instanceof Error ? error.message : String(error) }, { status: 400 }),
)
}
@@ -149,9 +149,10 @@ app
if (actual.length !== secret.length || !timingSafeEqual(actual, secret)) return c.json({ error: "Unauthorized" }, 401)
const body = z.object({ shareID: z.string().min(1) }).safeParse(await c.req.json().catch(() => undefined))
if (!body.success) return c.json({ error: "Invalid request" }, 400)
await Share.removeAdmin({ id: body.data.shareID })
return c.json({})
if (!body.success) return c.json({ error: "Invalid request", issues: body.error.issues }, 400)
return Share.removeAdmin({ id: body.data.shareID })
.then(() => c.json({}))
.catch((error) => c.json({ error: error instanceof Error ? error.message : String(error) }, 400))
},
)