carto.js/docs/reference/05-error-handling.md
2020-06-13 18:34:34 +08:00

708 B

Error Handling

Most of the errors fired by the library are handled by the client itself. The client will trigger a CartoError every time an error happens.

A cartoError is an object containing a single message field with a string explaining the error.

Some methods in CARTO.js are asynchronous. This means that they return a promise that will be fulfilled when the asynchronous work is done or rejected with a CartoError when an error occurs.

// All errors are passed to the client.
client.on(carto.events.ERROR, cartoError => {
    console.error(cartoError.message):
})

// .addLayer() is async.
client.addLayer(newLayer)
    .then(successCallback)
    .catch(errorCallback);