Override the default error handler for the RestDataConnector.
The error handler is a function that handles the RestResponse returned form the RESTFul web service call when the request is unsuccessful (the HTTP code is not 200). Overriding this function is useful for extracting API-specific response formats and for interpreting error codes.
// 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 services.errors.createAuthorisationError("Unauthorized", response.code);
default:
throw services.errors.createRequestError("Request error", response.code);
}
};
restDataConnector.setResponseHandler(handleError);
The error handler is a function that handles the RestResponse returned form the RESTFul web service call when the request is unsuccessful (the HTTP code is not 200). Overriding this function is useful for extracting API-specific response formats and for interpreting error codes.
Further documentation.
JavaScript example: