From 52af1ef10bd139386abe72e281332884b013f658 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 16 Nov 2024 02:17:49 +0200 Subject: [PATCH] Refactor axios.js: remove unused axios utility functions to streamline codebase --- frontend/src/utils/axios.js | 74 ------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 frontend/src/utils/axios.js diff --git a/frontend/src/utils/axios.js b/frontend/src/utils/axios.js deleted file mode 100644 index eb73c74..0000000 --- a/frontend/src/utils/axios.js +++ /dev/null @@ -1,74 +0,0 @@ -import axios from "axios"; -import i18next from "i18next"; -import { acquire as fetchTuitioData } from "@flare/tuitio-client"; - -function getHeaders() { - const { token } = fetchTuitioData(); - const language = i18next.language; - - return { - "Content-Type": "application/json", - Authorization: `Tuitio ${token}`, - "Accept-Language": `${language}` - }; -} - -async function internalRequest(url, options) { - try { - const res = await axios.request(url, options); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - throw ( - { - ...error.response.data, - message: error.response.data.detail || error.response.data.title - } || error - ); - } - // The request was made but no response was received - // `error.request` is an instance of XMLHttpRequest in the browser and an instance of - // http.ClientRequest in node.js - throw error; - } -} - -export const request = (url, options) => internalRequest(url, options); - -export function post(url, data) { - const options = { - method: "post", - data: JSON.stringify(data), - headers: getHeaders() - }; - - return internalRequest(url, options); -} - -export function put(url, data) { - const options = { - method: "put", - data: JSON.stringify(data), - headers: getHeaders() - }; - - return internalRequest(url, options); -} - -export function del(url, data) { - const options = { - method: "delete", - data: JSON.stringify(data), - headers: getHeaders() - }; - - return internalRequest(url, options); -} - -export function get(url) { - const options = { - method: "GET", - headers: getHeaders() - }; - return internalRequest(url, options); -}