Menu

API Reference

Promise resolution

All methods in the Astro JS API return a promise. On success, the then handler takes a callback that will resolve with the value of the promise result, or no value if there is no return value:

plugin.promiseFunctionThatReturnsAValue().then(function(value) {
    //Success, `value` contains the result
});

plugin.promiseFunctionThatReturnsVoid().then(function() {
    //This promise doesn't resolve with a value, but it succeeded
});

On error, the catch handler function will receive a response parameter with the following structure:

{
    "message": String,
    "details": String
}

Handling errors

To handle errors in promise resolution, you should implement the catch function. The catch is a callback that receives the error that occurred as defined above. A typical implementation of error handling can be seen below:

plugin.promisedFunction('foo').then(function() {
    //Success
}).catch(function(error) {
    //Something went wrong
});