Skip to content

Commit

Permalink
[MDS-5860] Fix inconsistent toast error message from api calls (#3032)
Browse files Browse the repository at this point in the history
* remove throwing errors where no catch blocks exist

* remove unnecessary conditional

* updated test
  • Loading branch information
matbusby-fw authored Apr 3, 2024
1 parent 67bdff8 commit 7604956
Show file tree
Hide file tree
Showing 25 changed files with 202 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { success, error, request } from "../actions/genericActions";
import CustomAxios from "../customAxios";
import { storeActivities } from "../actions/activityActions";
import { AxiosResponse } from "axios";
import { IActivity } from "@mds/common";
import { IActivity } from "@mds/common/interfaces";
import {
ACTIVITIES,
ACTIVITIES_MARK_AS_READ,
Expand Down Expand Up @@ -37,9 +37,8 @@ export const fetchActivities = (
dispatch(storeActivities(response.data));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(GET_ACTIVITIES));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
Expand All @@ -54,9 +53,8 @@ export const markActivitiesAsRead = (activity_guids: string[]): AppThunk => (dis
.then(() => {
dispatch(success(GET_ACTIVITIES));
})
.catch((err) => {
.catch(() => {
dispatch(error(GET_ACTIVITIES));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
116 changes: 57 additions & 59 deletions services/common/src/redux/actionCreators/damActionCreator.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,74 @@
import { hideLoading, showLoading } from "react-redux-loading-bar";
import { notification } from "antd";
import { ENVIRONMENT } from "@mds/common";
import { ENVIRONMENT } from "@mds/common/constants";
import { CREATE_DAM, GET_DAM, UPDATE_DAM } from "@mds/common/constants/reducerTypes";
import { DAM, DAMS } from "@mds/common/constants/API";
import { error, request, success } from "../actions/genericActions";

import CustomAxios from "../customAxios";
import { createRequestHeader } from "../utils/RequestHeaders";
import { storeDam } from "../actions/damActions";
import { ICreateDam, IDam } from "@mds/common";
import { ICreateDam, IDam } from "@mds/common/interfaces";
import { AppThunk } from "@mds/common/interfaces/appThunk.type";
import { AxiosResponse } from "axios";

export const createDam =
(payload: ICreateDam): AppThunk<Promise<AxiosResponse<IDam>>> =>
(dispatch): Promise<AxiosResponse<IDam>> => {
dispatch(request(CREATE_DAM));
dispatch(showLoading());
export const createDam = (payload: ICreateDam): AppThunk<Promise<AxiosResponse<IDam>>> => (
dispatch
): Promise<AxiosResponse<IDam>> => {
dispatch(request(CREATE_DAM));
dispatch(showLoading());

return CustomAxios()
.post(`${ENVIRONMENT.apiUrl}${DAMS()}`, payload, createRequestHeader())
.then((response: AxiosResponse<IDam>) => {
notification.success({
message: "Successfully created new Dam",
duration: 10,
});
dispatch(success(CREATE_DAM));
return response;
})
.catch(() => {
dispatch(error(CREATE_DAM));
throw new Error("Failed to create Dam");
})
.finally(() => dispatch(hideLoading()));
};
return CustomAxios()
.post(`${ENVIRONMENT.apiUrl}${DAMS()}`, payload, createRequestHeader())
.then((response: AxiosResponse<IDam>) => {
notification.success({
message: "Successfully created new Dam",
duration: 10,
});
dispatch(success(CREATE_DAM));
return response;
})
.catch(() => {
dispatch(error(CREATE_DAM));
})
.finally(() => dispatch(hideLoading()));
};

export const updateDam =
(damGuid: string, payload: Partial<IDam>): AppThunk<Promise<AxiosResponse<IDam>>> =>
(dispatch): Promise<AxiosResponse<IDam>> => {
dispatch(request(UPDATE_DAM));
dispatch(showLoading());
export const updateDam = (
damGuid: string,
payload: Partial<IDam>
): AppThunk<Promise<AxiosResponse<IDam>>> => (dispatch): Promise<AxiosResponse<IDam>> => {
dispatch(request(UPDATE_DAM));
dispatch(showLoading());

return CustomAxios()
.patch(`${ENVIRONMENT.apiUrl}${DAM(damGuid)}`, payload, createRequestHeader())
.then((response) => {
dispatch(success(UPDATE_DAM));
dispatch(storeDam(response.data));
return response;
})
.catch((err) => {
dispatch(error(UPDATE_DAM));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
return CustomAxios()
.patch(`${ENVIRONMENT.apiUrl}${DAM(damGuid)}`, payload, createRequestHeader())
.then((response) => {
dispatch(success(UPDATE_DAM));
dispatch(storeDam(response.data));
return response;
})
.catch(() => {
dispatch(error(UPDATE_DAM));
})
.finally(() => dispatch(hideLoading()));
};

export const fetchDam =
(damGuid: string): AppThunk<Promise<AxiosResponse<IDam>>> =>
(dispatch): Promise<AxiosResponse<IDam>> => {
dispatch(request(GET_DAM));
dispatch(showLoading());
export const fetchDam = (damGuid: string): AppThunk<Promise<AxiosResponse<IDam>>> => (
dispatch
): Promise<AxiosResponse<IDam>> => {
dispatch(request(GET_DAM));
dispatch(showLoading());

return CustomAxios()
.get(`${ENVIRONMENT.apiUrl}${DAM(damGuid)}`, createRequestHeader())
.then((response: AxiosResponse<IDam>) => {
dispatch(success(GET_DAM));
dispatch(storeDam(response.data));
return response;
})
.catch((err) => {
dispatch(error(GET_DAM));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
return CustomAxios()
.get(`${ENVIRONMENT.apiUrl}${DAM(damGuid)}`, createRequestHeader())
.then((response: AxiosResponse<IDam>) => {
dispatch(success(GET_DAM));
dispatch(storeDam(response.data));
return response;
})
.catch(() => {
dispatch(error(GET_DAM));
})
.finally(() => dispatch(hideLoading()));
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import * as reducerTypes from "@mds/common/constants/reducerTypes";
import { hideLoading, showLoading } from "react-redux-loading-bar";

import { notification } from "antd";
import { ENVIRONMENT, IMineDocumentVersion } from "@mds/common";
import { ENVIRONMENT } from "@mds/common/constants";
import { IMineDocumentVersion } from "@mds/common/interfaces";
import { error, request, success } from "@mds/common/redux/actions/genericActions";
import CustomAxios from "@mds/common/redux/customAxios";
import * as API from "@mds/common/constants/API";
Expand Down Expand Up @@ -43,9 +44,8 @@ export const postNewDocumentVersion = ({
dispatch(success(reducerTypes.POST_NEW_DOCUMENT_VERSION));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.POST_NEW_DOCUMENT_VERSION));
throw new Error(err);
})
.finally(() => {
dispatch(hideLoading());
Expand All @@ -69,9 +69,8 @@ export const pollDocumentUploadStatus = (
dispatch(success(reducerTypes.POLL_DOCUMENT_UPLOAD_STATUS));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.POLL_DOCUMENT_UPLOAD_STATUS));
throw new Error(err);
})
.finally(() => {
dispatch(hideLoading());
Expand All @@ -91,9 +90,8 @@ export const documentsCompression = (mineGuid, documentManagerGuids) => (dispatc
dispatch(success(reducerTypes.DOCUMENTS_COMPRESSION));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.DOCUMENTS_COMPRESSION));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
Expand All @@ -111,9 +109,8 @@ export const pollDocumentsCompressionProgress = (taskId) => (dispatch) => {
dispatch(documentActions.storeDocumentCompressionProgress(response.data));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.POLL_DOCUMENTS_COMPRESSION_PROGRESS));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notification } from "antd";
import { showLoading, hideLoading } from "react-redux-loading-bar";
import { ENVIRONMENT, IExplosivesPermit } from "@mds/common";
import { ENVIRONMENT } from "@mds/common/constants";
import { IExplosivesPermit } from "@mds/common/interfaces";
import { request, success, error } from "../actions/genericActions";
import * as reducerTypes from "@mds/common/constants/reducerTypes";
import * as explosivesPermitActions from "../actions/explosivesPermitActions";
Expand Down Expand Up @@ -29,9 +30,8 @@ export const createExplosivesPermit = (
dispatch(success(reducerTypes.CREATE_EXPLOSIVES_PERMIT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.CREATE_EXPLOSIVES_PERMIT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading("modal")));
};
Expand All @@ -50,9 +50,8 @@ export const fetchExplosivesPermits = (
dispatch(explosivesPermitActions.storeExplosivesPermits(response.data));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.GET_EXPLOSIVES_PERMITS));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
Expand Down Expand Up @@ -80,9 +79,8 @@ export const updateExplosivesPermit = (
dispatch(success(reducerTypes.UPDATE_EXPLOSIVES_PERMIT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.UPDATE_EXPLOSIVES_PERMIT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading("modal")));
};
Expand All @@ -106,9 +104,8 @@ export const deleteExplosivesPermit = (
dispatch(success(reducerTypes.DELETE_EXPLOSIVES_PERMIT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.DELETE_EXPLOSIVES_PERMIT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notification } from "antd";
import { hideLoading, showLoading } from "react-redux-loading-bar";
import { ENVIRONMENT, IExplosivesPermitAmendment } from "@mds/common";
import { ENVIRONMENT } from "@mds/common/constants";
import { IExplosivesPermitAmendment } from "@mds/common/interfaces";
import { error, request, success } from "../actions/genericActions";
import * as reducerTypes from "@mds/common/constants/reducerTypes";
import * as API from "@mds/common/constants/API";
Expand Down Expand Up @@ -31,9 +32,8 @@ export const createExplosivesPermitAmendment = (
dispatch(success(reducerTypes.CREATE_EXPLOSIVES_PERMIT_AMENDMENT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.CREATE_EXPLOSIVES_PERMIT_AMENDMENT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading("modal")));
};
Expand Down Expand Up @@ -63,9 +63,8 @@ export const updateExplosivesPermitAmendment = (
dispatch(success(reducerTypes.UPDATE_EXPLOSIVES_PERMIT_AMENDMENT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.UPDATE_EXPLOSIVES_PERMIT_AMENDMENT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading("modal")));
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { showLoading, hideLoading } from "react-redux-loading-bar";
import { ENVIRONMENT } from "@mds/common";
import { ENVIRONMENT } from "@mds/common/constants";
import { request, success, error } from "../actions/genericActions";
import * as reducerTypes from "@mds/common/constants/reducerTypes";
import * as externalAuthActions from "../actions/externalAuthorizationActions";
Expand All @@ -18,9 +18,8 @@ export const fetchMineEpicInformation = (mineGuid) => (dispatch) => {
dispatch(externalAuthActions.storeEpicInfo(response.data, mineGuid));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.GET_MINE_EPIC_INFO));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
20 changes: 7 additions & 13 deletions services/common/src/redux/actionCreators/incidentActionCreator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { showLoading, hideLoading } from "react-redux-loading-bar";
import { notification } from "antd";
import { ENVIRONMENT } from "@mds/common";
import { ENVIRONMENT } from "@mds/common/constants";
import { request, success, error } from "../actions/genericActions";
import * as reducerTypes from "@mds/common/constants/reducerTypes";
import * as Strings from "@mds/common/constants/strings";
Expand Down Expand Up @@ -28,9 +28,8 @@ export const createMineIncident = (
dispatch(success(reducerTypes.CREATE_MINE_INCIDENT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.CREATE_MINE_INCIDENT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading("modal")));
};
Expand Down Expand Up @@ -90,9 +89,8 @@ export const updateMineIncident = (
dispatch(success(reducerTypes.UPDATE_MINE_INCIDENT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.UPDATE_MINE_INCIDENT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading("modal")));
};
Expand All @@ -115,9 +113,8 @@ export const removeDocumentFromMineIncident = (mineGuid, mineIncidentGuid, mineD
dispatch(success(reducerTypes.REMOVE_DOCUMENT_FROM_MINE_INCIDENT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.REMOVE_DOCUMENT_FROM_MINE_INCIDENT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
Expand Down Expand Up @@ -151,9 +148,8 @@ export const deleteMineIncident = (mineGuid, mineIncidentGuid) => (dispatch) =>
dispatch(success(reducerTypes.DELETE_MINE_INCIDENT));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.DELETE_MINE_INCIDENT));
throw new Error(err);
})
.finally(() => dispatch(hideLoading()));
};
Expand Down Expand Up @@ -187,9 +183,8 @@ export const createMineIncidentNote = (mineIncidentGuid, payload) => (dispatch)
dispatch(success(reducerTypes.CREATE_MINE_INCIDENT_NOTE));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.CREATE_MINE_INCIDENT_NOTE));
throw new Error(err);
});
};

Expand All @@ -208,8 +203,7 @@ export const deleteMineIncidentNote = (mineIncidentGuid, mineIncidentNoteGuid) =
dispatch(success(reducerTypes.DELETE_MINE_INCIDENT_NOTE));
return response;
})
.catch((err) => {
.catch(() => {
dispatch(error(reducerTypes.DELETE_MINE_INCIDENT_NOTE));
throw new Error(err);
});
};
Loading

0 comments on commit 7604956

Please sign in to comment.