Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// @ts-ignore
import { getAnomalyAggs } from '../get_anomaly_aggs';

test('getAnomalyAggs should swallow HTTP errors', () => {
const httpError = new Error('anomaly lookup failed') as any;
httpError.statusCode = 418;
const failClient = jest.fn(() => Promise.reject(httpError));

return expect(getAnomalyAggs({ client: failClient })).resolves.toEqual(null);
});

test('getAnomalyAggs should throw other errors', () => {
const otherError = new Error('anomaly lookup ASPLODED') as any;
const failClient = jest.fn(() => Promise.reject(otherError));

return expect(
getAnomalyAggs({
client: failClient
})
).rejects.toThrow(otherError);
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ export async function getAnomalyAggs({
try {
const resp = await client('search', params);
return resp.aggregations;
} catch (e) {
if (e.statusCode === 404) {
} catch (err) {
if ('statusCode' in err) {
// swallow HTTP errors because there are lots of reasons
// the ml index lookup may fail, and we're ok with that
return null;
}
throw e;

throw err;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getAvgResponseTimeAnomalies({

if (!aggs) {
return {
message: 'ml index does not exist'
message: 'Error reading machine learning index'
};
}

Expand Down