Error handling
All services return a standard Promise-based response, so the error handling is straightforward:
xg.recommend.getResultsById({elementId: '<element_id>'}).then((result) => {
// success...
console.log('Result:', result);
}).catch((error) => {
// error...
console.log('Error:', error);
});
// OR if you are using the async/await syntax:
try {
const result = xg.recommend.getResultsById({elementId: '<element_id>'});
console.log('Result:', result);
} catch (error) {
console.log('Error:', error);
}
The response error is normalized and always returned as ResponseError object with the following public fields that you could use:
ResponseError {
url: string, // requested url
status: number, // response status code
response: { ... }, // the API JSON error response
isAbort: boolean, // is abort/cancellation error
originalError: Error|null, // the original non-normalized error
}