Merge pull request #1361 from ecordell/application-problem-json
Return application/problem+json format errors
This commit is contained in:
commit
29eb0304e5
30 changed files with 309 additions and 141 deletions
|
@ -211,8 +211,9 @@ quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', 'PlanServi
|
|||
|
||||
// Handle session expiration.
|
||||
Restangular.setErrorInterceptor(function(response) {
|
||||
if (response.status == 401 && response.data['error_type'] == 'invalid_token' &&
|
||||
response.data['session_required'] !== false) {
|
||||
//TODO: remove check for error_type (old style errors)
|
||||
var invalid_token = response.data['title'] == 'invalid_token' || response.data['error_type'] == 'invalid_token';
|
||||
if (response.status == 401 && invalid_token && response.data['session_required'] !== false) {
|
||||
$('#sessionexpiredModal').modal({});
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -51,4 +51,4 @@ angular.module('quay').directive('signupForm', function () {
|
|||
}
|
||||
};
|
||||
return directiveDefinitionObject;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -129,7 +129,7 @@
|
|||
$scope.showInterface = true;
|
||||
}, function(resp) {
|
||||
$scope.users = [];
|
||||
$scope.usersError = resp['data']['message'] || resp['data']['error_description'];
|
||||
$scope.usersError = ApiService.getErrorMessage(resp);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -365,4 +365,4 @@
|
|||
// Load the initial status.
|
||||
$scope.checkStatus();
|
||||
}
|
||||
}());
|
||||
}());
|
||||
|
|
|
@ -124,7 +124,9 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService'
|
|||
var deferred = $q.defer();
|
||||
|
||||
// If the error is a fresh login required, show the dialog.
|
||||
if (resp.status == 401 && resp.data['error_type'] == 'fresh_login_required') {
|
||||
// TODO: remove error_type (old style error)
|
||||
var fresh_login_required = resp.data['title'] == 'fresh_login_required' || resp.data['error_type'] == 'fresh_login_required';
|
||||
if (resp.status == 401 && fresh_login_required) {
|
||||
var retryOperation = function() {
|
||||
apiService[opName].apply(apiService, opArgs).then(function(resp) {
|
||||
deferred.resolve(resp);
|
||||
|
@ -293,7 +295,8 @@ angular.module('quay').factory('ApiService', ['Restangular', '$q', 'UtilService'
|
|||
apiService.getErrorMessage = function(resp, defaultMessage) {
|
||||
var message = defaultMessage;
|
||||
if (resp['data']) {
|
||||
message = resp['data']['error_message'] || resp['data']['message'] || resp['data']['error_description'] || message;
|
||||
//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;
|
||||
}
|
||||
|
||||
return message;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Service which provides helper methods for performing some simple UI operations.
|
||||
*/
|
||||
angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$location', function($timeout, $rootScope, $location) {
|
||||
angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$location', 'ApiService', function($timeout, $rootScope, $location, ApiService) {
|
||||
var CheckStateController = function(items, itemKey) {
|
||||
this.items = items;
|
||||
this.checked = [];
|
||||
|
@ -12,6 +12,7 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio
|
|||
this.itemKey_ = itemKey;
|
||||
this.listeners_ = [];
|
||||
this.page_ = null;
|
||||
this.ApiService = ApiService
|
||||
};
|
||||
|
||||
CheckStateController.prototype.listen = function(callback) {
|
||||
|
@ -138,7 +139,7 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio
|
|||
};
|
||||
|
||||
uiService.showFormError = function(elem, result, opt_placement) {
|
||||
var message = result.data['message'] || result.data['error_description'] || '';
|
||||
var message = ApiService.getErrorMessage(result, 'error');
|
||||
if (message) {
|
||||
uiService.showPopover(elem, message, opt_placement || 'bottom');
|
||||
} else {
|
||||
|
|
Reference in a new issue