@ -5,7 +5,8 @@ const winston = require('winston');
const validator = require ( 'validator' ) ;
const plugins = require ( '../plugins' ) ;
const middleware = require ( '../middleware' ) ;
const helpers = require ( '../middleware/helpers' ) ;
const middlewareHelpers = require ( '../middleware/helpers' ) ;
const helpers = require ( './helpers' ) ;
exports . handleURIErrors = async function handleURIErrors ( err , req , res , next ) {
// Handle cases where malformed URIs are passed in
@ -53,15 +54,18 @@ exports.handleErrors = function handleErrors(err, req, res, next) { // eslint-di
return res . locals . isAPI ? res . set ( 'X-Redirect' , err . path ) . status ( 200 ) . json ( err . path ) : res . redirect ( nconf . get ( 'relative_path' ) + err . path ) ;
}
winston . error ( ` ${ req . path } \n ${ err . stack } ` ) ;
const path = String ( req . path || '' ) ;
res . status ( status || 500 ) ;
if ( path . startsWith ( ` ${ nconf . get ( 'relative_path' ) } /api/v3 ` ) ) {
return helpers . formatApiResponse ( err . message . startsWith ( '[[' ) ? 400 : 500 , res , err ) ;
}
const path = String ( req . path || '' ) ;
winston . error ( ` ${ req . path } \n ${ err . stack } ` ) ;
res . status ( status || 500 ) ;
const data = {
path : validator . escape ( path ) ,
error : validator . escape ( String ( err . message ) ) ,
bodyClass : h elpers. buildBodyClass ( req , res ) ,
bodyClass : middlewareH elpers. buildBodyClass ( req , res ) ,
} ;
if ( res . locals . isAPI ) {
res . json ( data ) ;