skinny-azureS
Refine3y ago
14 replies
skinny-azure

handle axios console error coming from useCreate

``import { HttpError } from "@refinedev/core"; import axios, { AxiosRequestConfig } from "axios"; export const TOKEN_KEY = "***"; const axiosInstance = axios.create({ baseURL: "http://127.0.0.1:5000/api", }); axiosInstance.interceptors.request.use( (request: AxiosRequestConfig) => { // Retrieve the token from local storage const token = localStorage.getItem(TOKEN_KEY); // Check if the header property exists if (request.headers) { // Set the Authorization header if it exists request.headers["Authorization"] = `Bearer ${token}`; } else { // Create the headers property if it does not exist request.headers = { Authorization: `Bearer ${token}`, }; } return request; }, (error) => { // Do something with request error return Promise.reject(error); } ); axiosInstance.interceptors.response.use( (response) => { return response; }, (error) => { const customError: HttpError = { ...error, message: error.response?.data?.message, statusCode: error.response?.status, }; return Promise.reject(customError); } ); export { axiosInstance };

how do i handle the console error thrown probably useCreate or axios
image.png
Was this page helpful?