code: function serveErr(_req, res, next) {
      return async function (err) {
          if (err.message === 'next') {
              return next();
          }
          console.log('ERROR', err);
          console.log('STACK', err.stack);
          let text = 'ERROR' + (err.code ? ' ' + err.code : '') + ': ' + err.message;
          exports.globalOpts.serveErr.propertiesWhiteList.forEach(function (attrName) {
              if (attrName in err) {
                  text += '\n' + attrName + ': ' + JSON.stringify(err[attrName]);
              }
          });
          if (exports.globalOpts.serveErr.sendStack) {
              text += '\n------------------\n' + err.stack;
          }
          if (!res.headersSent) {
              let buf = new Buffer(text);
              let length = buf.length;
              res.writeHead(err.status || 400, {
                  'Content-Length': length,
                  'Content-Type': 'text/plain; charset=utf-8'
              });
          }
          else {
              text += "\n</script>\n<pre>\n------------------------------------\n" + text;
          }
          res.end(text);
      };
  }
docs: /* tslint:enable:no-object-literal-type-assertion