Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling when config index is not found #173

Merged
merged 1 commit into from
Feb 11, 2022
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
6 changes: 6 additions & 0 deletions server/services/DestinationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

import _ from 'lodash';
import { isIndexNotFoundError } from './utils/helpers';

export default class DestinationsService {
constructor(esDriver) {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions server/services/MonitorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import _ from 'lodash';

import { INDEX } from '../../utils/constants';
import { isIndexNotFoundError } from './utils/helpers';

export default class MonitorService {
constructor(esDriver) {
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion server/services/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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]'
);
};