mirror of
https://github.com/bitwarden/web
synced 2025-12-06 00:03:28 +00:00
better error message handling
This commit is contained in:
@@ -35,13 +35,9 @@
|
|||||||
toastr.success('The attachment has been added.');
|
toastr.success('The attachment has been added.');
|
||||||
closing = true;
|
closing = true;
|
||||||
$uibModalInstance.close(true);
|
$uibModalInstance.close(true);
|
||||||
}, function (err) {
|
}, function (e) {
|
||||||
if (err) {
|
var errors = validationService.parseErrors(e);
|
||||||
validationService.addError(form, 'file', err, true);
|
toastr.error(errors.length ? errors[0] : 'An error occurred.');
|
||||||
}
|
|
||||||
else {
|
|
||||||
validationService.addError(form, 'file', 'Something went wrong.', true);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
return _service;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,13 +45,9 @@
|
|||||||
fileEl.type = '';
|
fileEl.type = '';
|
||||||
fileEl.type = 'file';
|
fileEl.type = 'file';
|
||||||
fileEl.value = '';
|
fileEl.value = '';
|
||||||
}, function (err) {
|
}, function (e) {
|
||||||
if (err) {
|
var errors = validationService.parseErrors(e);
|
||||||
validationService.addError(form, 'file', err, true);
|
toastr.error(errors.length ? errors[0] : 'An error occurred.');
|
||||||
}
|
|
||||||
else {
|
|
||||||
validationService.addError(form, 'file', 'Something went wrong.', true);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
.module('bit.vault')
|
.module('bit.vault')
|
||||||
|
|
||||||
.controller('vaultController', function ($scope, $uibModal, apiService, $filter, cryptoService, authService, toastr,
|
.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.loading = true;
|
||||||
$scope.ciphers = [];
|
$scope.ciphers = [];
|
||||||
$scope.folderCount = 0;
|
$scope.folderCount = 0;
|
||||||
@@ -496,8 +496,9 @@
|
|||||||
selectAll(false);
|
selectAll(false);
|
||||||
$scope.bulkActionLoading = false;
|
$scope.bulkActionLoading = false;
|
||||||
toastr.success('Items have been deleted!');
|
toastr.success('Items have been deleted!');
|
||||||
}, function () {
|
}, function (e) {
|
||||||
toastr.error('An error occurred.');
|
var errors = validationService.parseErrors(e);
|
||||||
|
toastr.error(errors.length ? errors[0] : 'An error occurred.');
|
||||||
$scope.bulkActionLoading = false;
|
$scope.bulkActionLoading = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user