Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bforms Ajax error event triggered even if eg serverError handled #282

Open
meister-d opened this issue Sep 23, 2016 · 0 comments
Open

bforms Ajax error event triggered even if eg serverError handled #282

meister-d opened this issue Sep 23, 2016 · 0 comments

Comments

@meister-d
Copy link

Hi Guys
in bforms Ajax i encountered following scenario:

when handling serverError and error, i get my Error Messages twice:

var ajaxOptions = {
                    name: '|setGroups|',
                    url: this.options.index.setGroupsUrl,
                    type: 'post',
                    context: this,
                    data: { value: e.currentTarget.dataset.value },
                    context: this,
                    success: function (response, args) {
                        var r = response;
                        if (r.Status == 1) //Success
                        {
                            if (r.Data == undefined || r.Data.Status == undefined) {
                                PersonalPresenceIndex.prototype._addSuccess(r.Message);
                                PersonalPresenceIndex.prototype._alertTimeout(5000);
                            }
                            else //We have Data filled. It seems that there is an exception happening 
                            {
                                if (r.Data.Status == 4) {
                                    PersonalPresenceIndex.prototype._addAlert(r.Data.Message);
                                    PersonalPresenceIndex.prototype._alertTimeout(10000);
                                }
                            }
                        }
                        else {
                            if (r.Status == 4) //Server Error
                            {
                                PersonalPresenceIndex.prototype._addAlert(r.Message);
                                PersonalPresenceIndex.prototype._alertTimeout(10000);
                            }
                        }
                    },
                    validationError: function(response)
                    {
                        var r = response;
                        PersonalPresenceIndex.prototype._addAlert(r.Message);
                        PersonalPresenceIndex.prototype._alertTimeout(10000);
                    },
                    serverError: function(response)
                    {
                        var r = response;
                        PersonalPresenceIndex.prototype._addAlert(r.Message);
                        PersonalPresenceIndex.prototype._alertTimeout(10000);
                    },
                    denied: function(response)
                    {
                        var r = response;
                        PersonalPresenceIndex.prototype._addAlert(r.Message);
                        PersonalPresenceIndex.prototype._alertTimeout(10000);
                    },
                    error: function (response) {
                        var r = response;
                        PersonalPresenceIndex.prototype._addAlert(r.Message);
                        PersonalPresenceIndex.prototype._alertTimeout(10000);

                    },
                    loadingElement: $('.groupToggle'),
                    loadingClass: 'loading'
                };
                $.bforms.ajax(ajaxOptions);

Im my opinion it should be an else if handling here, as if I have already handled one specific type of handler, i dont want to handle it also for the more general error:

deferredXHR.done($.proxy(function (status, args) {
            if (status === this._statusEnum.Success) {
                if (typeof opts.success === "function") {
                    opts.success.apply(opts.context, args);
                }
            } else if (status === this._statusEnum.ValidationError) {
                if (typeof opts.validationError === "function") {
                    opts.validationError.apply(opts.context, args);
                }

                else if (typeof opts.error === "function") {
                    opts.error.apply(opts.context, args);
                }
            }

            if (status === this._statusEnum.ServerError) {
                if (typeof opts.serverError === "function") {
                    opts.serverError.apply(opts.context, args);
                }

                else if (typeof opts.error === "function") {
                    opts.error.apply(opts.context, args);
                }
            }
            if (status === this._statusEnum.Denied) {

                this._handleUnauthorized.apply(self, [xhrSettings]);

                if (typeof opts.denied === "function") {
                    opts.denied.apply(opts.context, args);
                }

                else if (typeof opts.error === "function") {
                    opts.error.apply(opts.context, args);
                }
            }

        }, this));

        deferredXHR.fail($.proxy(function (status, args) {

            if (status === this._statusEnum.ServerError) {
                if (typeof opts.serverError === "function") {
                    opts.serverError.apply(opts.context, args);
                }
            } else if (status === this._statusEnum.Denied) {

                this._handleUnauthorized.apply(self, [xhrSettings]);

                if (typeof opts.denied === "function") {
                    opts.denied.apply(opts.context, args);
                }
            }

            else if (status === this._statusEnum.Timeout) {
                if (typeof opts.onTimeout === "function") {
                    opts.onTimeout.apply(opts.context, args);
                }
            }

            else if (status === this._statusEnum.Offline) {
                if (typeof opts.offline === "function") {
                    opts.offline.apply(opts.context, args);
                }
            }

            else if (typeof opts.error === "function") {
                opts.error.apply(opts.context, args);
            }
        }, this));

Regards Dumitru

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant