0

I spent several hours on this problem and I can not figure this out :( I know that I tested that functionality about a week or so ago and I saw 2 toastr error messages displayed (I didn't want two of them, though). I am not sure what exactly changed but now I can not get even a single one displayed :( I see no toastr message at all.

My code is:

app.directive('serverError', ['resourceFactory', 'spinnerService', 'toastr', '$log',
        function (resourceFactory, spinnerService, toastr, $log) {
        return {
            restrict: 'A',
            controller: ['$scope', '$timeout', function ($scope, $timeout) {
                log = $log.getInstance("serverError");

                var errorToastConfig = {
                    closeButton: true,
                    timeOut: 0,
                    extendedTimeOut: 0,
                    tapToDismiss: false,
                    preventDuplicates: true
                };

                var title = resourceFactory.getResource("Messages", "applicationError");
                $scope.$on('sm:badRequest', function (event, data) {
                    
                    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;
                       
                        toastr.clear();
                        if (errorMsg=="")
                            errorMsg = resourceFactory.getResource('Messages', 'errorOnForm');

                        title = resourceFactory.getResource("Messages", "badRequest");
                        toastr.error(errorMsg, title, errorToastConfig);
                    }
                    $scope.disableAction = false;
                });

And then also in the controller:

function (error) {
                        spinnerService.stopSpinner('loaditemtree');
                        $scope.stopExecution = true;
                        if (error.hasOwnProperty("data")) {
                            toastr.clear();
                            let errorMsg = error.data[0].message;
                            toastr.error(errorMsg);
                        }                        
                    });

I see in the console [ItImagesSearchController] Init of the Images Search Controller is firing... /SiriuswareControl/api/itDraftHeaders/1019 Failed to load resource: the server responded with a status of 400 (Bad Request) 2angular.js:14525 [serverError] Handling bad request

I also trace my code in the controller and I can see the line with toastr being executed. However, I see no toastr :( What can possibly be wrong?

Naomi
  • 718
  • 1
  • 9
  • 28

1 Answers1

0

I believe I figured this out, but I am sort of back to square 1. I wanted to prevent duplicate toastr messages from being displayed, thus I have preventDuplicates: true in the server error toastr config. However, it somehow made none of the messages to be displayed. When I slightly changed message in my controller, I saw both toastr messages now. How can I make only one of them to show?

Naomi
  • 718
  • 1
  • 9
  • 28
  • I set MaxOpened property to 1 and now at least I don't see all 3 of them at once. I don't know why do I see 'Handling Bad Request' twice, though... – Naomi Mar 27 '18 at 22:17