1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

move feature-metrics-api

This commit is contained in:
sveisvei 2016-12-04 20:01:12 +01:00
parent 14a0b1dba7
commit cd34dd8e89
3 changed files with 14 additions and 32 deletions

View File

@ -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,
};

View File

@ -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';

View File

@ -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,
};