diff --git a/server/services/DestinationsService.js b/server/services/DestinationsService.js index 345c2b1ee..92bbfd98d 100644 --- a/server/services/DestinationsService.js +++ b/server/services/DestinationsService.js @@ -25,6 +25,7 @@ */ import _ from 'lodash'; +import { isIndexNotFoundError } from './utils/helpers'; export default class DestinationsService { constructor(esDriver) { @@ -198,6 +199,11 @@ export default class DestinationsService { }, }); } catch (err) { + if (isIndexNotFoundError(err)) { + return res.ok({ + body: { ok: true, resp: { totalDestinations: 0, destinations: [] } }, + }); + } return res.ok({ body: { ok: false, diff --git a/server/services/MonitorService.js b/server/services/MonitorService.js index b2567cdc9..a83979d87 100644 --- a/server/services/MonitorService.js +++ b/server/services/MonitorService.js @@ -27,6 +27,7 @@ import _ from 'lodash'; import { INDEX } from '../../utils/constants'; +import { isIndexNotFoundError } from './utils/helpers'; export default class MonitorService { constructor(esDriver) { @@ -350,6 +351,11 @@ export default class MonitorService { }); } catch (err) { console.error('Alerting - MonitorService - getMonitors', err); + if (isIndexNotFoundError(err)) { + return res.ok({ + body: { ok: false, resp: { totalMonitors: 0, monitors: [] } }, + }); + } return res.ok({ body: { ok: false, diff --git a/server/services/utils/helpers.js b/server/services/utils/helpers.js index e022e3381..fbf0f8630 100644 --- a/server/services/utils/helpers.js +++ b/server/services/utils/helpers.js @@ -24,7 +24,7 @@ * permissions and limitations under the License. */ -import { map, mapKeys, mapValues, isPlainObject, snakeCase, camelCase } from 'lodash'; +import { get, map, mapKeys, mapValues, isPlainObject, snakeCase, camelCase } from 'lodash'; export function mapKeysDeep(obj, fn) { if (Array.isArray(obj)) { @@ -39,3 +39,11 @@ export function mapKeysDeep(obj, fn) { export const toSnake = (value, key) => snakeCase(key); export const toCamel = (value, key) => camelCase(key); + +export const isIndexNotFoundError = (err) => { + return ( + err.statusCode === 404 && + get(err, 'body.error.reason', '') === + 'Configured indices are not found: [.opendistro-alerting-config]' + ); +};