module . exports = ( { } , app ) => { return async ( ctx , next ) => { try { await next ( ) ; } catch ( err ) { app . logger . error ( err ) ; const status = err . status || 500 ; const error = status === 500 && app . config . env === 'prod' ? 'Internal Server Error' : err . message ; ctx . body = { code : status , error , } ; if ( status === 422 ) { ctx . body . detail = err . errors ; } ctx . status = 200 ; } } ; } ;