fix(js/signin-form): check for resp body first

This commit is contained in:
EvB 2017-01-05 15:31:29 -05:00
parent bdb86fdc10
commit bd027b9cbc
2 changed files with 20 additions and 11 deletions

View file

@ -23,10 +23,10 @@ angular.module('quay').directive('signinForm', function () {
$scope.signInUser = {};
$scope.markStarted = function() {
$scope.signingIn = true;
if ($scope.signInStarted != null) {
$scope.signInStarted();
}
$scope.signingIn = true;
if ($scope.signInStarted != null) {
$scope.signInStarted();
}
};
$scope.cancelInterval = function() {
@ -110,6 +110,10 @@ angular.module('quay').directive('signinForm', function () {
}, function(result) {
$scope.signingIn = false;
if (!result || !result.status /* malformed response */) {
return bootbox.alert(ApiService.getErrorMessage(result));
}
if (result.status == 429 /* try again later */) {
$scope.needsEmailVerification = false;
$scope.invalidCredentials = false;
@ -124,13 +128,18 @@ angular.module('quay').directive('signinForm', function () {
$scope.cancelInterval();
}
}, 1000, $scope.tryAgainSoon);
} else if (result.status == 400) {
bootbox.alert(ApiService.getErrorMessage(result));
} else {
$scope.needsEmailVerification = result.data.needsEmailVerification;
$scope.invalidCredentials = result.data.invalidCredentials;
$scope.invalidCredentialsMessage = result.data.message;
return;
}
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.invalidCredentials = result.data.invalidCredentials;
$scope.invalidCredentialsMessage = result.data.message;
});
};
}

View file

@ -290,7 +290,7 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService'
apiService.getErrorMessage = function(resp, defaultMessage) {
var message = defaultMessage;
if (resp['data']) {
if (resp && resp['data']) {
//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;
}