From 29dd4602d122ba084797ad178e9ebe2eb90f4cc7 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Thu, 3 May 2018 22:39:51 +0100 Subject: [PATCH] [ML] Fixing error reporting in message bar (#18781) (#18788) --- .../ml/public/datavisualizer/datavisualizer_controller.js | 6 +++--- .../job_timepicker_modal/job_timepicker_modal_controller.js | 5 +++-- x-pack/plugins/ml/public/ml_nodes_check/check_ml_nodes.js | 2 +- x-pack/plugins/ml/public/services/http_service.js | 6 +----- x-pack/plugins/ml/public/services/job_service.js | 4 ++-- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/ml/public/datavisualizer/datavisualizer_controller.js b/x-pack/plugins/ml/public/datavisualizer/datavisualizer_controller.js index cd503043dea4f5..8a3ac92eab2dd3 100644 --- a/x-pack/plugins/ml/public/datavisualizer/datavisualizer_controller.js +++ b/x-pack/plugins/ml/public/datavisualizer/datavisualizer_controller.js @@ -494,7 +494,7 @@ module .catch((err) => { // TODO - display error in cards saying data could not be loaded. console.log('DataVisualizer - error getting stats for metric cards from elasticsearch:', err); - if (err.status === 500) { + if (err.statusCode === 500) { notify.error(`Error loading data for metrics in index ${indexPattern.title}. ${err.message}. ` + 'The request may have timed out. Try using a smaller sample size or narrowing the time range.', { lifetime: 30000 }); @@ -545,7 +545,7 @@ module .catch((err) => { // TODO - display error in cards saying data could not be loaded. console.log('DataVisualizer - error getting non metric field stats from elasticsearch:', err); - if (err.status === 500) { + if (err.statusCode === 500) { notify.error(`Error loading data for fields in index ${indexPattern.title}. ${err.message}. ` + 'The request may have timed out. Try using a smaller sample size or narrowing the time range.', { lifetime: 30000 }); @@ -595,7 +595,7 @@ module .catch((err) => { // TODO - display error in cards saying data could not be loaded. console.log('DataVisualizer - error getting overall stats from elasticsearch:', err); - if (err.status === 500) { + if (err.statusCode === 500) { notify.error(`Error loading data for fields in index ${indexPattern.title}. ${err.message}. ` + 'The request may have timed out. Try using a smaller sample size or narrowing the time range.', { lifetime: 30000 }); diff --git a/x-pack/plugins/ml/public/jobs/jobs_list/job_timepicker_modal/job_timepicker_modal_controller.js b/x-pack/plugins/ml/public/jobs/jobs_list/job_timepicker_modal/job_timepicker_modal_controller.js index 394874d288a0e7..ab6351f9b92bdc 100644 --- a/x-pack/plugins/ml/public/jobs/jobs_list/job_timepicker_modal/job_timepicker_modal_controller.js +++ b/x-pack/plugins/ml/public/jobs/jobs_list/job_timepicker_modal/job_timepicker_modal_controller.js @@ -95,16 +95,17 @@ module.controller('MlJobTimepickerModal', function ( doStart(); }) .catch((resp) => { - if (resp.status === 409) { + if (resp.statusCode === 409) { doStart(); } else { - if (resp.status === 500) { + if (resp.statusCode === 500) { if (doStartCalled === false) { // doStart hasn't been called yet, this 500 has returned before 10s, // so it's not due to a timeout msgs.error(`Could not open ${$scope.jobId}`, resp); } } else { + // console.log(resp); msgs.error(`Could not open ${$scope.jobId}`, resp); } $scope.saveLock = false; diff --git a/x-pack/plugins/ml/public/ml_nodes_check/check_ml_nodes.js b/x-pack/plugins/ml/public/ml_nodes_check/check_ml_nodes.js index a0f01f72b9eab6..8d1e9cec49abef 100644 --- a/x-pack/plugins/ml/public/ml_nodes_check/check_ml_nodes.js +++ b/x-pack/plugins/ml/public/ml_nodes_check/check_ml_nodes.js @@ -30,7 +30,7 @@ export function getMlNodeCount() { }) .catch((error) => { mlNodeCount = 0; - if (error.status === 403) { + if (error.statusCode === 403) { userHasPermissionToViewMlNodeCount = false; } else { console.error(error); diff --git a/x-pack/plugins/ml/public/services/http_service.js b/x-pack/plugins/ml/public/services/http_service.js index e2704ea7695645..5a7e4d9c1d70f2 100644 --- a/x-pack/plugins/ml/public/services/http_service.js +++ b/x-pack/plugins/ml/public/services/http_service.js @@ -39,11 +39,7 @@ export function http(options) { fetch(url, payload) .then((resp) => { - if (resp.ok === true) { - resolve(resp.json()); - } else { - reject(resp); - } + resp.json().then((resp.ok === true) ? resolve : reject); }) .catch((resp) => { reject(resp); diff --git a/x-pack/plugins/ml/public/services/job_service.js b/x-pack/plugins/ml/public/services/job_service.js index 06df3f28da02cf..1e8eb5109cf407 100644 --- a/x-pack/plugins/ml/public/services/job_service.js +++ b/x-pack/plugins/ml/public/services/job_service.js @@ -492,7 +492,7 @@ class JobService { } function deleteFailed(resp, txt) { - if (resp.status === 500) { + if (resp.statusCode === 500) { status.errorMessage = txt; } reject({ success: false }); @@ -905,7 +905,7 @@ class JobService { }) .catch((err) => { console.log('jobService error stopping datafeed:', err); - if (err.status === 500) { + if (err.statusCode === 500) { msgs.error('Could not stop datafeed for ' + jobId); msgs.error('Request may have timed out and may still be running in the background.'); } else {