Merge pull request #2267 from coreos-inc/FIX-frontend-errors
fix(js): ensure method calls safe
This commit is contained in:
commit
56db2f5fd8
3 changed files with 32 additions and 17 deletions
|
@ -39,6 +39,9 @@ angular.module('quay').directive('setRepoPermissions', function () {
|
||||||
|
|
||||||
var checkForChanges = function() {
|
var checkForChanges = function() {
|
||||||
var hasChanges = false;
|
var hasChanges = false;
|
||||||
|
if (!$scope.repositories) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$scope.repositories.forEach(function(repo) {
|
$scope.repositories.forEach(function(repo) {
|
||||||
if (repo['permission'] != repo['original_permission']) {
|
if (repo['permission'] != repo['original_permission']) {
|
||||||
|
@ -51,6 +54,9 @@ angular.module('quay').directive('setRepoPermissions', function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
var handleRepoCheckChange = function() {
|
var handleRepoCheckChange = function() {
|
||||||
|
if (!$scope.repositories) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$scope.repositories.forEach(function(repo) {
|
$scope.repositories.forEach(function(repo) {
|
||||||
if ($scope.checkedRepos.isChecked(repo)) {
|
if ($scope.checkedRepos.isChecked(repo)) {
|
||||||
if (repo['permission'] == 'none') {
|
if (repo['permission'] == 'none') {
|
||||||
|
@ -121,6 +127,11 @@ angular.module('quay').directive('setRepoPermissions', function () {
|
||||||
$scope.currentNamespace = $scope.namespace;
|
$scope.currentNamespace = $scope.namespace;
|
||||||
|
|
||||||
var repos = [];
|
var repos = [];
|
||||||
|
if (!resp || !resp['repositories'] || resp['repositories'].length == 0) {
|
||||||
|
$scope.repositoriesLoaded({'repositories': []});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
resp['repositories'].forEach(function(repo) {
|
resp['repositories'].forEach(function(repo) {
|
||||||
var existingPermission = existingPermissionsMap[repo.name] || 'none';
|
var existingPermission = existingPermissionsMap[repo.name] || 'none';
|
||||||
|
|
||||||
|
@ -134,11 +145,6 @@ angular.module('quay').directive('setRepoPermissions', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (repos.length == 0) {
|
|
||||||
$scope.repositoriesLoaded({'repositories': repos});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.repositories = repos;
|
$scope.repositories = repos;
|
||||||
$scope.checkedRepos = UIService.createCheckStateController($scope.repositories, 'name');
|
$scope.checkedRepos = UIService.createCheckStateController($scope.repositories, 'name');
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,10 @@ angular.module('quay').directive('signinForm', function () {
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
$scope.signingIn = false;
|
$scope.signingIn = false;
|
||||||
|
|
||||||
|
if (!result || !result.status /* malformed response */) {
|
||||||
|
return bootbox.alert(ApiService.getErrorMessage(result));
|
||||||
|
}
|
||||||
|
|
||||||
if (result.status == 429 /* try again later */) {
|
if (result.status == 429 /* try again later */) {
|
||||||
$scope.needsEmailVerification = false;
|
$scope.needsEmailVerification = false;
|
||||||
$scope.invalidCredentials = false;
|
$scope.invalidCredentials = false;
|
||||||
|
@ -124,13 +128,18 @@ angular.module('quay').directive('signinForm', function () {
|
||||||
$scope.cancelInterval();
|
$scope.cancelInterval();
|
||||||
}
|
}
|
||||||
}, 1000, $scope.tryAgainSoon);
|
}, 1000, $scope.tryAgainSoon);
|
||||||
} else if (result.status == 400) {
|
|
||||||
bootbox.alert(ApiService.getErrorMessage(result));
|
return;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (!result.data || result.status == 400 /* bad request */) {
|
||||||
|
return bootbox.alert(ApiService.getErrorMessage(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* success - set scope values to response */
|
||||||
$scope.needsEmailVerification = result.data.needsEmailVerification;
|
$scope.needsEmailVerification = result.data.needsEmailVerification;
|
||||||
$scope.invalidCredentials = result.data.invalidCredentials;
|
$scope.invalidCredentials = result.data.invalidCredentials;
|
||||||
$scope.invalidCredentialsMessage = result.data.message;
|
$scope.invalidCredentialsMessage = result.data.message;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,7 +290,7 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService'
|
||||||
|
|
||||||
apiService.getErrorMessage = function(resp, defaultMessage) {
|
apiService.getErrorMessage = function(resp, defaultMessage) {
|
||||||
var message = defaultMessage;
|
var message = defaultMessage;
|
||||||
if (resp['data']) {
|
if (resp && resp['data']) {
|
||||||
//TODO: remove error_message and error_description (old style error)
|
//TODO: remove error_message and error_description (old style error)
|
||||||
message = resp['data']['detail'] || resp['data']['error_message'] || resp['data']['message'] || resp['data']['error_description'] || message;
|
message = resp['data']['detail'] || resp['data']['error_message'] || resp['data']['message'] || resp['data']['error_description'] || message;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue