43 lines
877 B
TypeScript
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)
|
|
}
|