diff --git a/lib/server/middlewareButNotReally/isIdNan.ts b/lib/server/middlewareButNotReally/isIdNan.ts new file mode 100644 index 0000000..d2542c1 --- /dev/null +++ b/lib/server/middlewareButNotReally/isIdNan.ts @@ -0,0 +1,12 @@ +import { EventHandlerRequest, H3Event } from "h3"; + +export default function (ev: H3Event) { + const id = parseInt(getRouterParam(ev, "id")!); + if (Number.isNaN(id)) { + throw createError({ + statusCode: 400, + message: "Invalid id provided.", + }); + } + return id; +}