code: function extractErrors(obj) {
    if (obj instanceof Error) {
      return [obj];
    }
    var errors = [];
  
    if (obj) {
      Object.keys(obj).forEach(function(key) {
        var val = obj[key];
  
        if (val instanceof Error) {
          errors.push(val);
          delete obj[key];
        }
      });
    }
  
    return errors;
  }
docs: Scans the object passed as argument looking for Error values. The values that
  matched are removed from the object and placed in the array returned by the
  function.
  
  Only the top-level properties of the object are checked, the function doesn't
  search the object recursively.
  
  @param {Object} obj The object to extract errors from.
  
  @return {Array} The list of errors extracted from the object.