Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
formatESError(error) {
if (error instanceof KuzzleError) {
return error;
}
if (error instanceof es.errors.NoLivingConnectionsError) {
errorsManager.throw('not_connected');
}
const message = _.get(error, 'meta.body.error.reason', error.message);
// Try to match a known elasticsearch error
for (const mapping of errorMessagesMapping) {
const matches = message.match(mapping.regex);
if (matches) {
return errorsManager.get(
mapping.subcode,
...mapping.getPlaceholders(matches));
}
}
// Try to match using error codes