diff --git a/frontend/src/data/feature-metrics-api.js b/frontend/src/data/feature-metrics-api.js new file mode 100644 index 0000000000..8c2cd155de --- /dev/null +++ b/frontend/src/data/feature-metrics-api.js @@ -0,0 +1,13 @@ +const { throwIfNotSuccess } = require('./helper'); + +const URI = '/api/client/metrics/feature-toggles'; + +function fetchFeatureMetrics () { + return fetch(URI) + .then(throwIfNotSuccess) + .then(response => response.json()); +} + +module.exports = { + fetchFeatureMetrics, +}; diff --git a/frontend/src/store/feature-metrics-actions.js b/frontend/src/store/feature-metrics-actions.js index 4dc8eb66a6..a238e0098e 100644 --- a/frontend/src/store/feature-metrics-actions.js +++ b/frontend/src/store/feature-metrics-actions.js @@ -1,4 +1,4 @@ -import api from './feature-metrics-api'; +import api from '../data/feature-metrics-api'; export const START_FETCH_FEATURE_METRICS = 'START_FETCH_FEATURE_METRICS'; export const RECEIVE_FEATURE_METRICS = 'RECEIVE_FEATURE_METRICS'; diff --git a/frontend/src/store/feature-metrics-api.js b/frontend/src/store/feature-metrics-api.js deleted file mode 100644 index d4b397183e..0000000000 --- a/frontend/src/store/feature-metrics-api.js +++ /dev/null @@ -1,31 +0,0 @@ -const defaultErrorMessage = 'Unexptected exception when talking to unleash-api'; - -const URI = '/api/client/metrics/feature-toggles'; - -function throwIfNotSuccess (response) { - if (!response.ok) { - if (response.status > 400 && response.status < 404) { - return new Promise((resolve, reject) => { - response.json().then(body => { - const errorMsg = body && body.length > 0 ? body[0].msg : defaultErrorMessage; - let error = new Error(errorMsg); - error.statusCode = response.status; - reject(error); - }); - }); - } else { - return Promise.reject(new Error(defaultErrorMessage)); - } - } - return Promise.resolve(response); -} - -function fetchFeatureMetrics () { - return fetch(URI) - .then(throwIfNotSuccess) - .then(response => response.json()); -} - -module.exports = { - fetchFeatureMetrics, -};