function (err) {
              var stack;
              if (err.hasOwnProperty('stack')) {
                stack = err.stack;
              } else {