The com.ebasetech.xi.services.Errors is a server side JavaScript object that contains functions that allows the creation of customizable error handling functionality specifically for the HTTP error response status returned from the server, for example a 404 Not Found error.
The error handlers are created using a description string and an error code. The errors are as follows:
When an error occurs the errorHandler function is called to handle errors. The default error handler throws the errors described above as exceptions that can be caught from the RESTDataConnector RESTFul web service call.
// Define a custom error handler
function handleError(response) {
switch(response.code) {
case 401:
// Send an email stating that the service is authorized
fields.unauthorizedError.value = response.body;
resources.sysAdmin.sendMail();
throw connectors.errors.createAuthorisationError("Unauthorized", response.code);
default:
throw connectors.errors.createRequestError("Request error", response.code);
}
};
try {
const restDataConnector = connectors.createRESTDataConnector("https://jukeboxapi.example.com/");
// Override the default error handler
restDataConnector.setErrorHandler(errors);
// Call an endpoint
const uri = restDataConnector.get("playlists");
var response = restDataConnector.get(uri);
// ...
} catch(e) {
// Show the user the error message
event.owner.addErrorMessage(e);
}
errorHandler
function is called to handle errors. The default error handler throws the errors described above as exceptions that can be caught from the RESTDataConnector RESTFul web service call.The error handler can be overidden. The error handler is set by calling the RESTDataConnector#setErrorHandler(Function) function.
Further documentation.
JavaScript example: