app.factory('badRequestInterceptor', ['$rootScope', '$q', function ($rootScope, $q) { return { 'responseError': function (rejection) { if (rejection.status === 400) { $rootScope.$broadcast("sm:badRequest", rejection.data); } return $q.reject(rejection); } }; }]);Similar code for other types of errors.
return { restrict: 'A', controller: ['$scope', '$timeout', function ($scope, $timeout) { log = $log.getInstance("serverError"); var errorToastConfig = { closeButton: true, tapToDismiss: true }; var title = resourceFactory.getResource("Messages", "applicationError"); $scope.$on('sm:badRequest', function (event, data) { $timeout(function () { spinnerService.stopSpinner(); }, 0); if (!$scope.errorHandled && !$scope.showForm) { log.debug("Handling bad request"); let errorMsg = ""; angular.forEach(data, function (value, key) { if (value.message == '') value.message = 'The ' + value.property + ' value is invalid.' errorMsg = errorMsg + value.message + " "; }); errorMsg = errorMsg.trim(); $scope.errors = data; if (errorMsg=="") errorMsg = resourceFactory.getResource('Messages', 'errorOnForm'); title = resourceFactory.getResource("Messages", "badRequest"); toastr.remove(); toastr.error(errorMsg, title, errorToastConfig); } $scope.disableAction = false; });The edit form has this directive, e.g.
<form name="form" novalidate role="form" sm-dirty-check on-ok="dirtyOk()" server-error ng-hide="!showForm" class="ng-cloak">So, when I throw an error from my API controller, I see in Developer's console red error about bad request and then two 'Handling Bad Request' messages. I can not figure out why do I have two of them and not just one.