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:
parent
14a0b1dba7
commit
cd34dd8e89
13
frontend/src/data/feature-metrics-api.js
Normal file
13
frontend/src/data/feature-metrics-api.js
Normal 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,
|
||||
};
|
@ -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';
|
||||
|
@ -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,
|
||||
};
|
Loading…
Reference in New Issue
Block a user