mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Backport PR #8509
---------
**Commit 1:**
[esErrors/isTermSizeZeroError] always return true/false
When the error coming from the elasticsearch.js client is not as expected, isTermSizeZeroError throws a TypeError. This seems incorrect, the function should just return true or false in just about any scenario.
* Original sha: cdaab8d902
* Authored by spalger <email@spalger.com> on 2016-09-30T22:48:21Z
This commit is contained in:
parent
96a6ec34b8
commit
e382560c9b
3 changed files with 17 additions and 3 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue