js/modules/router.js
function jsonCloseError(options) {
    if (options === void 0) { options = {}; }
    options.debugLocalNetwork = options.debugLocalNetwork == null ? true : options.debugLocalNetwork;
    return function (err, req, res, next) {
        try {
            err = toError(err);
            var statusMessage = err.message || err.code;
            var statusCode = err.status || err.statusCode || 500;
            statusMessage = cleanStatusMessage(statusMessage);
            statusCode = statusCode.toString().replace(/[^0-9]/g, '');
            res.statusMessage = statusMessage;
            res.statusCode = statusCode;
            var rtn = {
                error: {
                    message: statusMessage,
                    code: statusCode,
                    "debug": {
                        "stack": err.stack
                    }
                }
            };
            var isDebug = err.stack && (options.debug || (options.debugLocalNetwork && ack.reqres(req, res).req.isLocalNetwork()));
            if (isDebug) {
                rtn.error["stack"] = err.stack; //debug requests will get stack traces
            }
            /*
                  if(res.json){
                    res.json(rtn)
                  }else{
                    var output = JSON.stringify(rtn)
                    res.setHeader('message', statusMessage)
                    res.setHeader('Content-Type','application/json')
                    res.setHeader('Content-Length', output.length.toString())
                    res.end( output );
                  }
            */
            var output = JSON.stringify(rtn);
            res.setHeader('message', statusMessage);
            res.setHeader('Content-Type', 'application/json');
            res.setHeader('Content-Length', output.length.toString());
            res.end(output);
        }
        catch (e) {
            console.error('ack/modules/reqres/res.js jsonCloseError failed hard');
            console.error(e);
            console.error('------ original error ------', statusMessage);
            console.error(err);
            if (next) {
                next(err);
            }
            else {
                throw err;
            }
        }
    };
}
function jsonCloseError(options) {
    if (options === void 0) { options = {}; }
    options.debugLocalNetwork = options.debugLocalNetwork == null ? true : options.debugLocalNetwork;
    return function (err, req, res, next) {
        try {
            err = toError(err);
            var statusMessage = err.message || err.code;
            var statusCode = err.status || err.statusCode || 500;
            statusMessage = cleanStatusMessage(statusMessage);
            statusCode = statusCode.toString().replace(/[^0-9]/g, '');
            res.statusMessage = statusMessage;
            res.statusCode = statusCode;
            var rtn = {
                error: {
                    message: statusMessage,
                    code: statusCode,
                    "debug": {
                        "stack": err.stack
                    }
                }
            };
            var isDebug = err.stack && (options.debug || (options.debugLocalNetwork && ack.reqres(req, res).req.isLocalNetwork()));
            if (isDebug) {
                rtn.error["stack"] = err.stack; //debug requests will get stack traces
            }
            /*
                  if(res.json){
                    res.json(rtn)
                  }else{
                    var output = JSON.stringify(rtn)
                    res.setHeader('message', statusMessage)
                    res.setHeader('Content-Type','application/json')
                    res.setHeader('Content-Length', output.length.toString())
                    res.end( output );
                  }
            */
            var output = JSON.stringify(rtn);
            res.setHeader('message', statusMessage);
            res.setHeader('Content-Type', 'application/json');
            res.setHeader('Content-Length', output.length.toString());
            res.end(output);
        }
        catch (e) {
            console.error('ack/modules/reqres/res.js jsonCloseError failed hard');
            console.error(e);
            console.error('------ original error ------', statusMessage);
            console.error(err);
            if (next) {
                next(err);
            }
            else {
                throw err;
            }
        }
    };
}
function jsonCloseError ( options ) { if ( options === void 0 ) { options = { } ; } options . debugLocalNetwork = options . debugLocalNetwork == null ? true : options . debugLocalNetwork ; return function ( err , req , res , next ) { try { err = toError ( err ) ; var statusMessage = err . message || err . code ; var statusCode = err . status || err . statusCode || 500 ; statusMessage = cleanStatusMessage ( statusMessage ) ; statusCode = statusCode . toString ( ) . replace ( / [^0-9] / g , '' ) ; res . statusMessage = statusMessage ; res . statusCode = statusCode ; var rtn = { error : { message : statusMessage , code : statusCode , "debug" : { "stack" : err . stack } } } ; var isDebug = err . stack && ( options . debug || ( options . debugLocalNetwork && ack . reqres ( req , res ) . req . isLocalNetwork ( ) ) ) ; if ( isDebug ) { rtn . error [ "stack" ] = err . stack ; //debug requests will get stack traces } /*
                  if(res.json){
                    res.json(rtn)
                  }else{
                    var output = JSON.stringify(rtn)
                    res.setHeader('message', statusMessage)
                    res.setHeader('Content-Type','application/json')
                    res.setHeader('Content-Length', output.length.toString())
                    res.end( output );
                  }
            */ var output = JSON . stringify ( rtn ) ; res . setHeader ( 'message' , statusMessage ) ; res . setHeader ( 'Content-Type' , 'application/json' ) ; res . setHeader ( 'Content-Length' , output . length . toString ( ) ) ; res . end ( output ) ; } catch ( e ) { console . error ( 'ack/modules/reqres/res.js jsonCloseError failed hard' ) ; console . error ( e ) ; console . error ( '------ original error ------' , statusMessage ) ; console . error ( err ) ; if ( next ) { next ( err ) ; } else { throw err ; } } } ; }
returns middleware that handles errors with JSON style details
@options {debug:true/false, debugLocalNetwork:true}
returns middleware that handles errors with JSON style details