Client side error handling

Hi there again!

We have many Plumsail forms across many sites and our clients keep informing us of errors in those forms that we can normally solve but have no idea why those errors occured. Is it JS, is it something with forms, is it sth else... ?
So my question is, how can I capture these errors in Plumsail?
For example, say that the client wants to upload a document in list library control with rootfolder xyz, but the folder was not available at that moment to the client because of trimmed SharePoint security.

What are your suggestions? what are the possibilities with plumsail?

fd.spRendered(function () {
    fd.control('SPDataTable2').ready(function (dt) {
        console.log('List or Library is initialized');
        try {
            dt.$on('change', function (changeData) {
                console.log('********** Change, Here???');
            })
            dt.$on('edit', function (changeData) {
                console.log('********** edit, Here???');
            })
            dt.$on('filesUploaded', function (changeData) {
                console.log('********** filesuploaded, Here???');
            })
        } catch (e1) {
            throw e1
        }
    })
});


window.addEventListener("error", listener);


function listener(event) {
    console.log("Listner???", event);
    if (event.error instanceof Error) {
        const errorData = {
            name: event.error.name,
            message: event.error.message,
            url: event.error.filename || document.location.href, // Use filename if available
            stack: event.error.stack,
            lineNo: event.lineno
        };
        console.error("Error captured:", errorData); 
       //At this point Add the caught error to another SharePoint list for example
    }
}

Thanks for your answer!

Edit: Tagging @IliaLazarevskii @mnikitina

Hi @asmita_adh,

Plumsail Forms doesn't have dedicated tools for exception handling.
All the necessary information can be found in the console or the Network tab of DevTools.

In your example, SharePoint's endpoint returned the error with the description from the screenshot:

Most probably, the form stayed open too long and the client's access token has expired. Refreshing the page and uploading the files again should help.

Hello @IliaLazarevskii,

Well of course I can see it in the console(as developer) but I can hardly ask end-users to go to console to find the errors, screenshot those and send it to us? Refreshing the page or browser back is also not a optimal solution.
We really need to capture errors caused in Plumsail forms. I am not looking for tools, just a simple try catch is fine but I cant capture it. Could you please see on your end why i cant capture these errors in plumsail?

Thanks in advance!

Hi @asmita_adh,

After some research, I'm not sure if this is possible. SharePoint forces its own error handler on the page, so standard JavaScript handlers like window.onerror and window.addEventListener() don't work.

I couldn't find a workaround, and I don't think Microsoft has any plans to change this. I'll let you know if I figure something out.

Hello,
Can you please explain this more.

Hi @liyanataufiq,

When an error occurs in JavaScript, it's usually just printed in the console. You can use window.onerror and window.addEventListener() to add custom error handlers to the page and execute some code when an error occurs (for example, send an error report or notify the user of the issue).

With SharePoint pages, it's not like this. SharePoint has its own error handler that takes priority over yours, so there's no way to execute code on error.
The same code that successfully catches all errors on a different page will not work in SharePoint.

Let me know if that answers your questions.