Files
web/server/errors/next.ts
2024-05-20 00:51:16 +02:00

43 lines
877 B
TypeScript

import { NextResponse } from "next/server"
export function badRequest(body: unknown | string = "Bad request") {
const resInit = {
status: 400,
statusText: "Bad request",
}
if (typeof body === "string") {
return new NextResponse(body, resInit)
}
return NextResponse.json(body, resInit)
}
export function notFound(body: unknown | string = "Not found") {
const resInit = {
status: 404,
statusText: "Not found",
}
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,
statusText: "Internal Server Error",
}
if (typeof body === "string") {
return new NextResponse(body, resInit)
}
return NextResponse.json(body, resInit)
}