import { ErrorRequestHandler , NextFunction , Request , Response } from 'express' ; import { DiagnosticsLogger } from '@ceramicnetwork/common' ; /**
 * Generic error handling middleware for the daemon.
 */ export function errorHandler ( logger ) { return ( err , req , res , next ) => { res . locals . error = err ; logger . err ( err ) ; if ( res . headersSent ) { return next ( err ) ; } if ( res . statusCode < 300 ) { res . status ( 500 ) ; } res . send ( { error : err . message } ) ; } ; }