@zeushq/nextjs-zapi
Version:
Next.js SDK for creating a Zeus API
28 lines (23 loc) • 681 B
text/typescript
import { NextApiResponse, NextApiRequest } from 'next';
import { HandleShow as BaseHandleShow } from '../zapi';
import { assertReqRes } from '../utils/assert';
import { HandlerError } from '../utils/errors';
/**
* The handler for the GET `api/[resource]/[id]` route.
*
* @category Server
*/
export type HandleShow = (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
/**
* @ignore
*/
export default function handleShowFactory(handler: BaseHandleShow): HandleShow {
return async (req, res): Promise<void> => {
try {
assertReqRes(req, res);
return await handler(req, res);
} catch (e) {
throw new HandlerError(e as any);
}
};
}