Files
web/server/errors/next.ts
2024-05-06 13:44:22 +02:00

28 lines
542 B
TypeScript

import { NextResponse } from "next/server"
export function badRequest(body: unknown | string = "Bad request") {
const resInit = {
status: 400,
}
if (typeof body === "string") {
return new NextResponse(body, resInit)
}
return NextResponse.json(body, resInit)
}
export function internalServerError(
body: unknown | string = "Internal Server Error"
) {
const resInit = {
status: 500,
}
if (typeof body === "string") {
return new NextResponse(body, resInit)
}
return NextResponse.json(body, resInit)
}