code: function (type, fn) {
    var result;
    try {
      result = fn();
    }
    catch (e) {
      result = {error: e};
    }
  
    if (result && !result.type && type)
      result.type = type;
  
    return result;
  }
docs: Try a login method, converting thrown exceptions into an {error} result.  The `type` argument is a default, inserted into the result object if not explicitly returned.