Skip to content

Request Errors

Chad Shurtz edited this page Aug 30, 2016 · 1 revision

Any application should be robust in dealing with unexpected errors, and OneNoteApi is no different. Each one of OneNoteApi's methods returning a Promise could reject with a RequestError object. This happens when an unexpected HTTP code is encountered (such as one as a result of a server error, or the result of bad parameters being passed to the API).

An example is provided below:

api.createNotebook("New Notebook").then(function(responsePackage) {
    console.log("Success!");
}, function(requestError) {
    console.log("Uh oh");
    console.log("Response: " + requestError.response);
    console.log("Timeout: " + requestError.timeout);
    console.log("Status code: " + requestError.statusCode);
    console.log("Response headers: " + requestError.responseHeaders);
});
Clone this wiki locally