import { NextApiRequest , NextApiResponse } from 'next' ; function import returns shares type NextController = ( req : NextApiRequest , res : NextApiResponse < unknown > ) => Promise < unknown > ; export default function catchErrorsFrom ( controller ) { return async ( req , res ) : Promise < unknown > => { return controller ( req , res ) . catch ( ( error ) => { console . error ( error ) ; return res . status ( 500 ) . json ( { success : 'fail' , error : error . message || error } ) ; } ) ; } ; }