Eksportér (0) Udskriv
Udvid alt
EN
Dette indhold er ikke tilgængeligt på dit sprog, men her er den engelske version.

Error handling

Updated: April 15, 2014

By default in a JavaScript backend mobile service, server scripts write errors to the log. In addition, operations that send a response, such as table operations and custom APIs write the error result to the response. To provide more control over script execution, you can also control error behaviors by specifying an error handler in your script. You typically implement explicit error handling when some sort of compensating action is possible or when you want to write more detailed information to the log using the global console object.

The following insert operation example augments the standard error log by writing the userId value of the current user in addition to the error object (err) itself.

function insert(item, user, request) {
    request.execute({
        error: function(err) {
            console.error("Error occurred for user '%s'. Details:", user.userId, err);
            request.respond();
        }
    });
}

For a custom API, write the appropriate error code directly to the response. The following GET request implementation returns a 500 error.

exports.get = function(request, response) {
    // This example just returns a 500 HTTP response.
    response.send(500, "An error occurred in your custom API code.");
};

For more information, see the Mobile Services script reference

Vis:
© 2014 Microsoft