Skip to content

Commit

Permalink
Merge pull request elastic#8509 from spalger/fix/is-term-size-zero-error
Browse files Browse the repository at this point in the history
[esErrors/isTermSizeZeroError] always return true/false
  • Loading branch information
spalger authored Oct 3, 2016
2 parents a23cd39 + cdaab8d commit fcf2930
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
11 changes: 11 additions & 0 deletions src/ui/public/elasticsearch_errors/elasticsearch_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 2 additions & 3 deletions src/ui/public/elasticsearch_errors/is_term_size_zero_error.js
Original file line number Diff line number Diff line change
@@ -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');
}

0 comments on commit fcf2930

Please sign in to comment.