Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove fireRequestV2 #8446

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 0 additions & 103 deletions src/Redux/fireRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as Notification from "../Utils/Notifications.js";

import { isEmpty, omitBy } from "lodash-es";

import { LocalStorageKeys } from "../Common/constants";
import api from "./api";
import axios from "axios";
Expand Down Expand Up @@ -173,104 +171,3 @@ export const fireRequest = (
});
};
};

export const fireRequestV2 = (
key: string,
path: any = [],
params: any = {},
successCallback: any = () => undefined,
errorCallback: any = () => undefined,
pathParam?: any,
altKey?: string,
) => {
// cancel previous api call
if (isRunning[altKey ? altKey : key]) {
isRunning[altKey ? altKey : key].cancel();
}
isRunning[altKey ? altKey : key] = axios.CancelToken.source();
// get api url / method
const request = Object.assign({}, requestMap[key]);
if (path.length > 0) {
request.path += "/" + path.join("/");
}
if (request.method === undefined || request.method === "GET") {
request.method = "GET";
const qs = new URLSearchParams(omitBy(params, isEmpty)).toString();
if (qs !== "") {
request.path += `?${qs}`;
}
}
// set dynamic params in the URL
if (pathParam) {
Object.keys(pathParam).forEach((param: any) => {
request.path = request.path.replace(`{${param}}`, pathParam[param]);
});
}

// set authorization header in the request header
const config: any = {
headers: {},
};
if (!request.noAuth && localStorage.getItem(LocalStorageKeys.accessToken)) {
config.headers["Authorization"] =
"Bearer " + localStorage.getItem(LocalStorageKeys.accessToken);
}
const axiosApiCall: any = axios.create(config);

fetchDataRequest(key);
return axiosApiCall[request.method.toLowerCase()](request.path, {
...params,
cancelToken: isRunning[altKey ? altKey : key].token,
})
.then((response: any) => {
successCallback(response.data);
})
.catch((error: any) => {
errorCallback(error);
if (error.response) {
// temporarily don't show invalid phone number error on duplicate patient check
if (error.response.status === 400 && key === "searchPatient") {
return;
}

// deleteUser: 404 is for permission denied
if (error.response.status === 404 && key === "deleteUser") {
Notification.Error({
msg: "Permission denied!",
});
}

// currentUser is ignored because on the first page load
// 403 error is displayed for invalid credential.
if (error.response.status === 403 && key === "currentUser") {
if (localStorage.getItem(LocalStorageKeys.accessToken)) {
localStorage.removeItem(LocalStorageKeys.accessToken);
}
}

// 400 Bad Request Error
if (error.response.status === 400 || error.response.status === 406) {
Notification.BadRequest({
errs: error.response.data,
});
}

// 4xx Errors
if (error.response.status > 400 && error.response.status < 600) {
if (error.response.data && error.response.data.detail) {
Notification.Error({
msg: error.response.data.detail,
});
} else {
Notification.Error({
msg: "Something went wrong...!",
});
}
if (error.response.status === 429) {
return error.response;
}
return;
}
}
});
};
Loading