Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Handle index not found error (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohltyler authored and yizheliu-amazon committed Aug 28, 2020
1 parent 31ec0aa commit 87e5c71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions server/routes/ad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
getFinalDetectorStates,
getDetectorsWithJob,
getDetectorInitProgress,
isIndexNotFoundError,
} from './utils/adHelpers';
import { set } from 'lodash';

Expand Down Expand Up @@ -303,13 +304,10 @@ const searchDetector = async (
},
};
} catch (err) {
if (
err.statusCode === 404 &&
get<string>(err, 'body.error.type', '') === 'index_not_found_exception'
) {
console.log('Anomaly detector - Unable to search detectors', err);
if (isIndexNotFoundError(err)) {
return { ok: true, response: { totalDetectors: 0, detectors: [] } };
}
console.log('Anomaly detector - Unable to search detectors', err);
return { ok: false, error: err.message };
}
};
Expand Down Expand Up @@ -515,7 +513,10 @@ const getDetectors = async (
},
};
} catch (err) {
console.log('Anomaly detector - Unable to list detectors', err);
console.log('Anomaly detector - Unable to search detectors', err);
if (isIndexNotFoundError(err)) {
return { ok: true, response: { totalDetectors: 0, detectorList: [] } };
}
return { ok: false, error: err.message };
}
};
Expand Down
7 changes: 7 additions & 0 deletions server/routes/utils/adHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,10 @@ export const getDetectorsWithJob = (

return resultDetectorWithJobs;
};

export const isIndexNotFoundError = (err: any) => {
return (
err.statusCode === 404 &&
get<string>(err, 'body.error.type', '') === 'index_not_found_exception'
);
};

0 comments on commit 87e5c71

Please sign in to comment.