mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
improve feedback when strategy create/update fails
This commit is contained in:
parent
fc8b01cf44
commit
24b0358113
@ -12,7 +12,7 @@ const prepare = (methods, dispatch) => {
|
|||||||
(e) => {
|
(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// clean
|
// clean
|
||||||
const parameters = input.parameters
|
const parameters = (input.parameters || [])
|
||||||
.filter((name) => !!name)
|
.filter((name) => !!name)
|
||||||
.map(({
|
.map(({
|
||||||
name,
|
name,
|
||||||
|
@ -27,7 +27,7 @@ const prepare = (methods, dispatch) => {
|
|||||||
(e) => {
|
(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// clean
|
// clean
|
||||||
const parameters = input.parameters
|
const parameters = (input.parameters || [])
|
||||||
.filter((name) => !!name)
|
.filter((name) => !!name)
|
||||||
.map(({
|
.map(({
|
||||||
name,
|
name,
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
const defaultErrorMessage = 'Unexptected exception when talking to unleash-api';
|
const defaultErrorMessage = 'Unexptected exception when talking to unleash-api';
|
||||||
|
|
||||||
|
function extractJoiMsg (body) {
|
||||||
|
return body.details.length > 0 ? body.details[0].message : defaultErrorMessage;
|
||||||
|
}
|
||||||
|
function extractLegacyMsg (body) {
|
||||||
|
return body && body.length > 0 ? body[0].msg : defaultErrorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
export function throwIfNotSuccess (response) {
|
export function throwIfNotSuccess (response) {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status > 399 && response.status < 404) {
|
if (response.status > 399 && response.status < 404) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
response.json().then(body => {
|
response.json().then(body => {
|
||||||
const errorMsg = body && body.length > 0 ? body[0].msg : defaultErrorMessage;
|
const errorMsg = body && body.isJoi ? extractJoiMsg(body) : extractLegacyMsg(body);
|
||||||
let error = new Error(errorMsg);
|
let error = new Error(errorMsg);
|
||||||
error.statusCode = response.status;
|
error.statusCode = response.status;
|
||||||
reject(error);
|
reject(error);
|
||||||
|
@ -7,6 +7,13 @@ import {
|
|||||||
ERROR_UPDATE_FEATURE_TOGGLE,
|
ERROR_UPDATE_FEATURE_TOGGLE,
|
||||||
} from './feature-actions';
|
} from './feature-actions';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ERROR_UPDATING_STRATEGY,
|
||||||
|
ERROR_CREATING_STRATEGY,
|
||||||
|
ERROR_RECEIVE_STRATEGIES,
|
||||||
|
|
||||||
|
} from './strategy/actions';
|
||||||
|
|
||||||
const debug = require('debug')('unleash:error-store');
|
const debug = require('debug')('unleash:error-store');
|
||||||
|
|
||||||
function getInitState () {
|
function getInitState () {
|
||||||
@ -29,6 +36,9 @@ const strategies = (state = getInitState(), action) => {
|
|||||||
case ERROR_REMOVE_FEATURE_TOGGLE:
|
case ERROR_REMOVE_FEATURE_TOGGLE:
|
||||||
case ERROR_FETCH_FEATURE_TOGGLES:
|
case ERROR_FETCH_FEATURE_TOGGLES:
|
||||||
case ERROR_UPDATE_FEATURE_TOGGLE:
|
case ERROR_UPDATE_FEATURE_TOGGLE:
|
||||||
|
case ERROR_UPDATING_STRATEGY:
|
||||||
|
case ERROR_CREATING_STRATEGY:
|
||||||
|
case ERROR_RECEIVE_STRATEGIES:
|
||||||
return addErrorIfNotAlreadyInList(state, action.error.message);
|
return addErrorIfNotAlreadyInList(state, action.error.message);
|
||||||
case MUTE_ERROR:
|
case MUTE_ERROR:
|
||||||
return state.update('list', (list) => list.remove(list.indexOf(action.error)));
|
return state.update('list', (list) => list.remove(list.indexOf(action.error)));
|
||||||
|
@ -21,11 +21,6 @@ const errorCreatingStrategy = (statusCode) => ({
|
|||||||
statusCode,
|
statusCode,
|
||||||
});
|
});
|
||||||
|
|
||||||
const errorUpdatingStrategy = (statusCode) => ({
|
|
||||||
type: ERROR_UPDATING_STRATEGY,
|
|
||||||
statusCode,
|
|
||||||
});
|
|
||||||
|
|
||||||
const startRequest = () => ({ type: REQUEST_STRATEGIES });
|
const startRequest = () => ({ type: REQUEST_STRATEGIES });
|
||||||
|
|
||||||
|
|
||||||
@ -43,6 +38,13 @@ const errorReceiveStrategies = (statusCode) => ({
|
|||||||
|
|
||||||
const startUpdate = () => ({ type: START_UPDATE_STRATEGY });
|
const startUpdate = () => ({ type: START_UPDATE_STRATEGY });
|
||||||
|
|
||||||
|
function dispatchAndThrow (dispatch, type) {
|
||||||
|
return (error) => {
|
||||||
|
dispatch({ type, error, receivedAt: Date.now() });
|
||||||
|
throw error;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function fetchStrategies () {
|
export function fetchStrategies () {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(startRequest());
|
dispatch(startRequest());
|
||||||
@ -69,7 +71,7 @@ export function updateStrategy (strategy) {
|
|||||||
|
|
||||||
return api.update(strategy)
|
return api.update(strategy)
|
||||||
.then(() => dispatch(updatedStrategy(strategy)))
|
.then(() => dispatch(updatedStrategy(strategy)))
|
||||||
.catch(error => dispatch(errorUpdatingStrategy(error)));
|
.catch(dispatchAndThrow(dispatch, ERROR_UPDATING_STRATEGY));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user