mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
better error message handling
This commit is contained in:
parent
2f13449cb6
commit
b411176c8d
@ -35,13 +35,9 @@
|
||||
toastr.success('The attachment has been added.');
|
||||
closing = true;
|
||||
$uibModalInstance.close(true);
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
validationService.addError(form, 'file', err, true);
|
||||
}
|
||||
else {
|
||||
validationService.addError(form, 'file', 'Something went wrong.', true);
|
||||
}
|
||||
}, function (e) {
|
||||
var errors = validationService.parseErrors(e);
|
||||
toastr.error(errors.length ? errors[0] : 'An error occurred.');
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -62,5 +62,41 @@
|
||||
}
|
||||
};
|
||||
|
||||
_service.parseErrors = function (reason) {
|
||||
var data = reason.data;
|
||||
var defaultErrorMessage = 'An unexpected error has occurred.';
|
||||
var errors = [];
|
||||
|
||||
if (!data || !angular.isObject(data)) {
|
||||
errors.push(defaultErrorMessage);
|
||||
return errors;
|
||||
}
|
||||
|
||||
if (data && data.ErrorModel) {
|
||||
data = data.ErrorModel;
|
||||
}
|
||||
|
||||
if (!data.ValidationErrors) {
|
||||
if (data.Message) {
|
||||
errors.push(data.Message);
|
||||
}
|
||||
else {
|
||||
errors.push(defaultErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
for (var key in data.ValidationErrors) {
|
||||
if (!data.ValidationErrors.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var i = 0; i < data.ValidationErrors[key].length; i++) {
|
||||
errors.push(data.ValidationErrors[key][i]);
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
return _service;
|
||||
});
|
||||
|
@ -45,13 +45,9 @@
|
||||
fileEl.type = '';
|
||||
fileEl.type = 'file';
|
||||
fileEl.value = '';
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
validationService.addError(form, 'file', err, true);
|
||||
}
|
||||
else {
|
||||
validationService.addError(form, 'file', 'Something went wrong.', true);
|
||||
}
|
||||
}, function (e) {
|
||||
var errors = validationService.parseErrors(e);
|
||||
toastr.error(errors.length ? errors[0] : 'An error occurred.');
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultController', function ($scope, $uibModal, apiService, $filter, cryptoService, authService, toastr,
|
||||
cipherService, $q, $localStorage, $timeout, $rootScope, $state, $analytics, constants) {
|
||||
cipherService, $q, $localStorage, $timeout, $rootScope, $state, $analytics, constants, validationService) {
|
||||
$scope.loading = true;
|
||||
$scope.ciphers = [];
|
||||
$scope.folderCount = 0;
|
||||
@ -496,8 +496,9 @@
|
||||
selectAll(false);
|
||||
$scope.bulkActionLoading = false;
|
||||
toastr.success('Items have been deleted!');
|
||||
}, function () {
|
||||
toastr.error('An error occurred.');
|
||||
}, function (e) {
|
||||
var errors = validationService.parseErrors(e);
|
||||
toastr.error(errors.length ? errors[0] : 'An error occurred.');
|
||||
$scope.bulkActionLoading = false;
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user