onErrorResponse handler not "firing"

Hi there
I am using webix filemanager (v 5.2.1 pro) that works excellently, but I am having trouble with setting up the onErrorResponse handler.

When there is an error uploading a file, I am returning

json_encode(false)

which shows the error "Error: changes were not saved". Fine.

The problem is that if another file is then dropped to the filemanager, it spins forever and the error message remains. (even thought the new file was successful)

I would like to prompt the user to re-upload the file, and reload the page to remove the error message. I am using this handler:


fManager.attachEvent("onErrorResponse", function(requestData,response){ console.log(requestData + " " +response); webix.confirm("There was an error uploading the file, please try again.").then(function(result){ window.location.reload(); }).fail(function(){ window.location.reload(); }); });

The problem is, this never fires and nothing is logged to console.

here is the entire webix code I am using:

  webix.ready(function () {

            let fManager = new webix.ui({
                view: "filemanager",
                container: "filemanager",
                handlers: {
                    "branch": "/api/fm_data_branch.php",
                    "upload": "/api/fm_upload.php",
                    "download": "/api/fm_download.php",
                    "copy": "/api/fm_copy.php",
                    "move": "/api/fm_move.php",
                    "remove": "/api/fm_remove.php",
                    "rename": "/api/fm_rename.php",
                    "create": "/api/fm_create.php"
                }
            });




            fManager.hideTree();
            fManager.load("/api/fm_data.php");

            let actions = fManager.getMenu();
            actions.remove("copy");
            actions.remove("cut");
            actions.remove("paste");
            actions.remove("create");
            actions.remove("remove");
            actions.remove("edit");




            fManager.attachEvent("onErrorResponse", function(requestData,response){

                console.log(requestData + " "  +response);

                webix.confirm("There was an error uploading the file, please try again.").then(function(result){
                    window.location.reload();

                }).fail(function(){
                    window.location.reload();

                });

            });



        })

Can someone please point me in the right direction?

Thanks

~mokiscott

Comments

  • Hello @mokiscott,

    The problem is that if another file is then dropped to the filemanager, it spins forever and the error message remains. (even thought the new file was successful)

    Seems like in this scenario the corresponding event that should call the hideProgress() method doesn’t get triggered, which is why you are getting stuck with an endless progress icon, even if the file got uploaded successfully afterwards. This is unintentional, and shouldn't work like that. As a temporary workaround, you can do this to fix the issue:

    $$("files").attachEvent("onBeforeUploadDialog", function(){
      this.getUploader().files.clearAll();
    })
    

    From our limited testing this is the most appropriate way to resolve the issue for the time being. Please try it out and tell us if this has helped you.

    I would like to prompt the user to re-upload the file, and reload the page to remove the error message. I am using this handler:

    I would like to know if this is something you are looking to do even if the issue could be avoided in the first place (according to the solution provided above). If that is the case, you could try using the onFileUploadError event handler of the inner uploader:

    $$("files").getUploader().attachEvent("onFileUploadError", function(obj) {
      // your logic
    });
    

    In the case that doesn't help you, could you please specify if the onErrorResponse handler doesn't get triggered even if the first uploaded file returned an error (after the page just got refreshed)?

  • edited January 17

    it is working now, I guess I wasn't attaching the onFileUploadError to the uploader, eg. the getUploader() part of this:

     fManager.getUploader().attachEvent("onFileUploadError", function (obj) {
    
                webix.confirm({
                    title: "Alert",
                    text: "There was an error uploading the file, please try again.",
                    type: "confirm-error",
                    callback:function(result){
    
                      // reload when OK or Cancel is clicked
                      window.location.reload();
                    }
                });
    
            });
    

    I can now avoid the endless spinner by reloading the page onFileUploadError .

    That works good enough for me! Thanks Dzmitry - you led me to a solution!

    PS.

    I tried the clearAll function you recommended also

    fManager.attachEvent("onBeforeUploadDialog", function(){
      this.getUploader().files.clearAll();
    })
    

    which does remove the spinner, but still leaves the "Error: changes were not saved" text at the bottom. New files were uploaded OK though.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!