Merge pull request #8517 from elastic/jasper/backport/8509/5.0

[backport] PR #8509 to 5.0 - [esErrors/isTermSizeZeroError] always return true/false
This commit is contained in:
Spencer 2016-10-03 12:11:10 -07:00 committed by GitHub
commit bdd055f18f
3 changed files with 17 additions and 3 deletions

View file

@ -30,4 +30,8 @@ describe('isTermSizeZeroError', () => {
};
expect(isTermSizeZeroError(error)).to.be(false);
});
it ('returns false for non-elasticsearch error input', () => {
expect(isTermSizeZeroError({ foo: 'bar' })).to.be(false);
});
});

View file

@ -15,6 +15,17 @@ export default class ElasticsearchError {
}
}
static hasRootCause(error, cause) {
try {
const esError = new ElasticsearchError(error);
return esError.hasRootCause(cause);
} catch (err) {
// we assume that any failure represents a validation error
// in the ElasticsearchError constructor
return false;
}
}
getRootCauses() {
const rootCauses = _.get(this.error, 'resp.error.root_cause');
return _.pluck(rootCauses, 'reason');

View file

@ -1,6 +1,5 @@
import ElasticsearchError from './elasticsearch_error';
import { hasRootCause } from './elasticsearch_error';
export default function isTermSizeZeroError(error) {
const esError = new ElasticsearchError(error);
return esError.hasRootCause('size must be positive, got 0');
return hasRootCause(error, 'size must be positive, got 0');
}