Skip to content

Commit

Permalink
Remove fireRequestV2 (#8446)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak authored Aug 31, 2024
1 parent 322818f commit d31a6a6
Showing 1 changed file with 0 additions and 103 deletions.
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;
}
}
});
};

0 comments on commit d31a6a6

Please sign in to comment.