request initial value gets overwritten. Why do you need and instance here?
You may not need that switch statement at all. You can use axios() like in this example // Send a POST request axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' } });
i don't even know why are we using this apiService.js, it is a method that is been using all across all the project basically... in the configuration object, they extract a JSON Web token from the localStorage(something that i tried to change, but they do not want me to do it), and that is the main reason why i am force to use it :/
you could do something like if ((data in response) && (response.data?.status === 'ERROR'))...
What do you need that line with axios.create for if the variable gets overwritten?
Ts assumes that the apiService returns an instance, though it actually always returns promise, because that request variable gets overwritten
Well uhh, axios.create() doesn't create a request, so request should probably never be assigned to axios.create(). Here's how I would write that (assuming I'm still using switch): switch (meta.method) { case "POST": { return axios.post(url, meta.body, configuration); } case "PUT": { return axios.put(url, meta.body, configuration); } case "DELETE": { return axios.delete(url, configuration); } default: { return axios.get(url, configuration); } }
Обсуждают сегодня