From 98f65405a790a0575ca20c987677f1f034c9d008 Mon Sep 17 00:00:00 2001 From: Satbir Singh Date: Wed, 17 Jun 2020 13:16:14 +0000 Subject: [PATCH] Handling api name change error. --- app/client/src/sagas/ActionSagas.ts | 61 +++++++++++++++++------------ 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/app/client/src/sagas/ActionSagas.ts b/app/client/src/sagas/ActionSagas.ts index 93d95ec538..6190b1f42c 100644 --- a/app/client/src/sagas/ActionSagas.ts +++ b/app/client/src/sagas/ActionSagas.ts @@ -816,32 +816,45 @@ export function* refactorActionName( function* saveApiNameSaga(action: ReduxAction<{ id: string }>) { // Takes from drafts, checks if the name isValid, saves - const apiNameDraftState = yield select(state => state.ui.apiPane.apiName); - const apiId = action.payload.id; - const apiNameDraft = apiNameDraftState.drafts[apiId]; - if (apiNameDraft) { - const validation = apiNameDraft.validation; - if (!validation.isValid) { - // If its invalid, then don't save and just remove draft and validation. - yield put( - updateApiNameDraft({ - id: action.payload.id, - }), - ); - } else { - const api = yield select(state => - state.entities.actions.find( - (action: ActionData) => action.config.id === apiId, - ), - ); + try { + const apiNameDraftState = yield select(state => state.ui.apiPane.apiName); + const apiId = action.payload.id; + const apiNameDraft = apiNameDraftState.drafts[apiId]; + if (apiNameDraft) { + const validation = apiNameDraft.validation; + if (!validation.isValid) { + // If its invalid, then don't save and just remove draft and validation. + yield put( + updateApiNameDraft({ + id: action.payload.id, + }), + ); + } else { + const api = yield select(state => + state.entities.actions.find( + (action: ActionData) => action.config.id === apiId, + ), + ); - yield refactorActionName( - api.config.id, - api.config.pageId, - api.config.name, - apiNameDraft.value, - ); + yield refactorActionName( + api.config.id, + api.config.pageId, + api.config.name, + apiNameDraft.value, + ); + } } + } catch (e) { + yield put( + updateApiNameDraft({ + id: action.payload.id, + }), + ); + AppToaster.show({ + message: `Unable to update API name`, + type: ToastType.ERROR, + }); + console.error(e); } }