next/lib/server/middlewareButNotReally/isIdNan.ts

13 lines
288 B
TypeScript
Raw Normal View History

import { EventHandlerRequest, H3Event } from "h3";
export default function (ev: H3Event<EventHandlerRequest>) {
const id = parseInt(getRouterParam(ev, "id")!);
if (Number.isNaN(id)) {
throw createError({
statusCode: 400,
message: "Invalid id provided.",
});
}
return id;
}