feat: improve structure and error handling

This commit is contained in:
Michael Zetterberg
2024-05-14 15:55:46 +02:00
parent 01587d7fd5
commit f5108d1a8e
104 changed files with 1505 additions and 1570 deletions

View File

@@ -3,6 +3,20 @@ 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") {
@@ -17,6 +31,7 @@ export function internalServerError(
) {
const resInit = {
status: 500,
statusText: "Internal Server Error",
}
if (typeof body === "string") {