1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-05 09:10:53 +01:00

Better error handling for imports. Check for bad CSV data on lastpass (when no header row is included).

This commit is contained in:
Kyle Spearrin 2016-11-09 00:41:17 -05:00
parent 93b96b3be7
commit 8313d9fa90
2 changed files with 43 additions and 8 deletions

View File

@ -172,7 +172,8 @@
function parseData(data) { function parseData(data) {
var folders = [], var folders = [],
sites = [], sites = [],
siteRelationships = []; siteRelationships = [],
badDataSites = 0;
angular.forEach(data, function (value, key) { angular.forEach(data, function (value, key) {
var folderIndex = folders.length, var folderIndex = folders.length,
@ -190,6 +191,10 @@
} }
} }
if ((!value.name || value.name === '') && (!value.password || value.password === '')) {
badDataSites++;
}
sites.push({ sites.push({
favorite: value.fav === '1', favorite: value.fav === '1',
uri: value.url && value.url !== '' ? trimUri(value.url) : null, uri: value.url && value.url !== '' ? trimUri(value.url) : null,
@ -214,9 +219,14 @@
} }
}); });
if (badDataSites > (data.length / 2)) {
error('CSV data is not formatted correctly from LastPass. Please check your import file and try again.');
}
else {
success(folders, sites, siteRelationships); success(folders, sites, siteRelationships);
} }
} }
}
function importSafeInCloudCsv(file, success, error) { function importSafeInCloudCsv(file, success, error) {
Papa.parse(file, { Papa.parse(file, {

View File

@ -31,17 +31,42 @@
}, importError); }, importError);
} }
function importError(errorMessage) { function importError(error) {
$analytics.eventTrack('Import Data Failed', { label: $scope.model.source }); $analytics.eventTrack('Import Data Failed', { label: $scope.model.source });
$uibModalInstance.dismiss('cancel'); $uibModalInstance.dismiss('cancel');
if (errorMessage) {
toastr.error(errorMessage); if (error) {
var data = error.data;
if (data && data.ValidationErrors) {
var message = '';
for (var key in data.ValidationErrors) {
if (!data.ValidationErrors.hasOwnProperty(key)) {
continue;
}
for (var i = 0; i < data.ValidationErrors[key].length; i++) {
message += (key + ': ' + data.ValidationErrors[key][i] + ' ');
}
}
if (message !== '') {
toastr.error(message);
return;
}
}
else if (data && data.Message) {
toastr.error(data.Message);
return;
} }
else { else {
toastr.error('Something went wrong. Try again.', 'Oh No!'); toastr.error(error);
return;
} }
} }
toastr.error('Something went wrong. Try again.', 'Oh No!');
}
$scope.close = function () { $scope.close = function () {
$uibModalInstance.dismiss('cancel'); $uibModalInstance.dismiss('cancel');
}; };