-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MDS-5860] Fix inconsistent toast error message from api calls (#3032)
* remove throwing errors where no catch blocks exist * remove unnecessary conditional * updated test
- Loading branch information
1 parent
67bdff8
commit 7604956
Showing
25 changed files
with
202 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 57 additions & 59 deletions
116
services/common/src/redux/actionCreators/damActionCreator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.