From ce425363b4297dc84bb9c0bc27d9b40c751985db Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 24 May 2018 00:41:37 +0300 Subject: [PATCH] Error message in GET /anomalies/status --- REST.md | 3 ++- server/src/routes/anomalies.ts | 2 +- server/src/services/analytics.ts | 2 +- server/src/services/anomalyType.ts | 8 +++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/REST.md b/REST.md index d0ba39e..d7ecf96 100644 --- a/REST.md +++ b/REST.md @@ -32,7 +32,8 @@ Return data format: ``` { - "status": + "status": , + "errorMessage": } ``` diff --git a/server/src/routes/anomalies.ts b/server/src/routes/anomalies.ts index 0a9dfb8..2024601 100644 --- a/server/src/routes/anomalies.ts +++ b/server/src/routes/anomalies.ts @@ -30,7 +30,7 @@ async function sendAnomalyTypeStatus(req, res) { if(anomaly.status === undefined) { 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) { console.error(e); // TODO: better send 404 when we know than isn`t found diff --git a/server/src/services/analytics.ts b/server/src/services/analytics.ts index 9de55d9..db49056 100644 --- a/server/src/services/analytics.ts +++ b/server/src/services/analytics.ts @@ -89,7 +89,7 @@ async function runLearning(anomalyId:AnomalyId) { insertSegments(anomalyId, result.segments, false); setAnomalyPredictionTime(anomalyId, result.last_prediction_time); } else { - setAnomalyStatus(anomalyId, 'failed'); + setAnomalyStatus(anomalyId, 'failed', result.error); } } diff --git a/server/src/services/anomalyType.ts b/server/src/services/anomalyType.ts index 81d280e..bf23943 100644 --- a/server/src/services/anomalyType.ts +++ b/server/src/services/anomalyType.ts @@ -25,6 +25,7 @@ export type Anomaly = { metric: Metric, datasource: Datasource status: string, + error?: string, last_prediction_time: number, next_id: number @@ -108,9 +109,14 @@ function getAnomalyTypeInfo(name) { 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); info.status = status; + if(error !== undefined) { + info.error = error; + } else { + info.error = ''; + } saveAnomaly(anomalyId, info); }