locked
LS 2012 HTML Client: Best way to globally intercept all error and excepton messages? RRS feed

  • Question

  • Hello,

    Our LS HTML Client application needs to globally intercept all error, validation, and exception messages that will be displayed to the user.  For example, if there is a concurrency issue, or any other exception... 

    What is the best manner to accomplish this goal? 

    Is there someplace in the JavaScript code through which all errors flow before being displayed to the user?

    Is there an established mechanism in LS for this (i.e. simply add an exception handler somewhere)?

    Do I need to modify LS source files (not my favorite solution)?  If so, which ones?

    I'd really appreciate your help with this question,

    Mike

    Friday, September 13, 2013 9:59 PM

Answers

  • ... In msls-1.0.0.js, I've found the following method.  It seems like all errors flow through it, and I could insert my code before reportError().  I need to look more closely...

            function endOperation(error, result) {
                if (!reportError && !reportComplete) {
                    return;
                }
                if (ambientOperation() !== operation) {
                    makeOperationCode(function endOperationCode() {
                        endOperation(error, result);
                    })();
                    return;
                }
                try {
                    if (error) {
                        reportError(error);
                    } else {
                        reportComplete(result);
                    }
                } finally {
                    reportError = reportComplete = null;
                }
            }

    • Marked as answer by A Bit of Help Thursday, September 19, 2013 12:37 AM
    Monday, September 16, 2013 9:06 PM
    • Marked as answer by A Bit of Help Thursday, September 19, 2013 12:37 AM
    Monday, September 16, 2013 11:14 PM
  • I decided that the errors that I need to intercept are really the ones from the server, so I am investigating how I want to intercept exceptions there...  For example, if a unique constraint is violated, etc.  Searching the Web right now...
    • Marked as answer by A Bit of Help Thursday, September 19, 2013 12:37 AM
    Wednesday, September 18, 2013 6:40 PM

All replies

  • Hi Everyone,

    I would think that other folks need to filter/adjust some LS messages...  Hopefully, I will get some hints...  :)

    Monday, September 16, 2013 7:39 PM
  • Hi,

    Thank you for your suggestion!  Unfortunately, I don't think that it will resolve our issue because it is tied to a particular screen: "You can save updates from one screen to multiple data sources ...".  It seems like all errors that are displayed to the user flow to a message box, so I may need to dig into the JS files and look at what is happening there...  Perhaps, insert my code in it... Not an ideal solution, but it may work...

    Monday, September 16, 2013 8:13 PM
  • All messages display to a message box if you don't catch them yourself. However I have only done this on a per operation basis.

    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Monday, September 16, 2013 8:23 PM
  • Yeah, this is what I've noticed, too...  Our application permits the user to rename a few entities in the solution, so they better match the user's environment and processes.  For example, a Customer may be renamed to Client.  Since error messages need to reflect this change of names in order to make the messages more meaningful, we need to intercept all errors and replace $$Customer$$ (default name of a table) with the user's replacement, (i.e. Client).  This is why I am investigating our options...  I think that in the end, I will need to locate where all errors flow to the MessageBox, and insert our code there.  Although our specific use case is somewhat unique, I could envision situation where others would like to inspect or alter errors before they are displayed to the user...  So, I was hoping that a mechanism may already exist. :P
    Monday, September 16, 2013 8:37 PM
  • ... In msls-1.0.0.js, I've found the following method.  It seems like all errors flow through it, and I could insert my code before reportError().  I need to look more closely...

            function endOperation(error, result) {
                if (!reportError && !reportComplete) {
                    return;
                }
                if (ambientOperation() !== operation) {
                    makeOperationCode(function endOperationCode() {
                        endOperation(error, result);
                    })();
                    return;
                }
                try {
                    if (error) {
                        reportError(error);
                    } else {
                        reportComplete(result);
                    }
                } finally {
                    reportError = reportComplete = null;
                }
            }

    • Marked as answer by A Bit of Help Thursday, September 19, 2013 12:37 AM
    Monday, September 16, 2013 9:06 PM
    • Marked as answer by A Bit of Help Thursday, September 19, 2013 12:37 AM
    Monday, September 16, 2013 11:14 PM
  • I decided that the errors that I need to intercept are really the ones from the server, so I am investigating how I want to intercept exceptions there...  For example, if a unique constraint is violated, etc.  Searching the Web right now...
    • Marked as answer by A Bit of Help Thursday, September 19, 2013 12:37 AM
    Wednesday, September 18, 2013 6:40 PM