Export (0) Print
Expand All

Script debugging

Updated: April 15, 2014

When working with server scripts in a JavaScript backend mobile service,, the easiest way to troubleshoot errors make use of the logs. When a script encounters an unhandled error, it is logged automatically. You can also write additional information directly to the logs using the console object.

The following example writes extra success and error information to the log.

function insert(item, user, request) {
    console.log("About to insert:", item);
    request.execute({
        success: function() {
            console.log("Successfully inserted:", item);
            request.respond();
        },
        error: function(err) {
            console.error("Error inserting:", item, err);
            request.respond();
        }
    });
}

Important: When you supply a success or error handler to the execute method of the request object, you must complete the handler by calling the respond method, which directs Mobile Services to write the response. Otherwise, the request will eventually time out.

The following are common sources of errors when working with scripts that are registered to data tables:

Failing to write call the respond method in all handler code paths.

Failing to handle a value of undefined returned by the user.userId property. This can happen when you allow unauthenticated access to tables. When you allow unauthenticated access, always check that userId is defined before using it in your script.

For more information, see the Mobile Services script reference

Show:
© 2014 Microsoft