Browse Source

Error message in GET /anomalies/status

pull/1/head
rozetko 7 years ago
parent
commit
ce425363b4
  1. 3
      REST.md
  2. 2
      server/src/routes/anomalies.ts
  3. 2
      server/src/services/analytics.ts
  4. 8
      server/src/services/anomalyType.ts

3
REST.md

@ -32,7 +32,8 @@ Return data format:
``` ```
{ {
"status": <str> "status": <str>,
"errorMessage": <str>
} }
``` ```

2
server/src/routes/anomalies.ts

@ -30,7 +30,7 @@ async function sendAnomalyTypeStatus(req, res) {
if(anomaly.status === undefined) { if(anomaly.status === undefined) {
throw new Error('No status for ' + name); throw new Error('No status for ' + name);
} }
res.status(200).send({ status: anomaly.status }); res.status(200).send({ status: anomaly.status, errorMessage: anomaly.error });
} catch(e) { } catch(e) {
console.error(e); console.error(e);
// TODO: better send 404 when we know than isn`t found // TODO: better send 404 when we know than isn`t found

2
server/src/services/analytics.ts

@ -89,7 +89,7 @@ async function runLearning(anomalyId:AnomalyId) {
insertSegments(anomalyId, result.segments, false); insertSegments(anomalyId, result.segments, false);
setAnomalyPredictionTime(anomalyId, result.last_prediction_time); setAnomalyPredictionTime(anomalyId, result.last_prediction_time);
} else { } else {
setAnomalyStatus(anomalyId, 'failed'); setAnomalyStatus(anomalyId, 'failed', result.error);
} }
} }

8
server/src/services/anomalyType.ts

@ -25,6 +25,7 @@ export type Anomaly = {
metric: Metric, metric: Metric,
datasource: Datasource datasource: Datasource
status: string, status: string,
error?: string,
last_prediction_time: number, last_prediction_time: number,
next_id: number next_id: number
@ -108,9 +109,14 @@ function getAnomalyTypeInfo(name) {
return getJsonDataSync(path.join(ANOMALIES_PATH, `${name}.json`)); return getJsonDataSync(path.join(ANOMALIES_PATH, `${name}.json`));
} }
function setAnomalyStatus(anomalyId:AnomalyId, status:string) { function setAnomalyStatus(anomalyId:AnomalyId, status:string, error?:string) {
let info = loadAnomalyById(anomalyId); let info = loadAnomalyById(anomalyId);
info.status = status; info.status = status;
if(error !== undefined) {
info.error = error;
} else {
info.error = '';
}
saveAnomaly(anomalyId, info); saveAnomaly(anomalyId, info);
} }

Loading…
Cancel
Save