-
Notifications
You must be signed in to change notification settings - Fork 33
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
Support axios >= 1.3.0 #124
Comments
axios-logger doesn't support 1.3.0 yet hg-pyun/axios-logger#124
axios-logger doesn't support 1.3.0 yet hg-pyun/axios-logger#124
Workaround that worked for me (TypeScript) until a proper patch is made: axios.interceptors.request.use((internalrequest: InternalAxiosRequestConfig) => {
const headers = internalrequest.headers;
const request: AxiosRequestConfig = {
...internalrequest,
};
const logrequest = AxiosLogger.requestLogger(request);
internalrequest = {
...logrequest,
...{ headers: headers },
};
return internalrequest;
}, AxiosLogger.errorLogger); |
I think I need to think about 1.3.0. I will think about it so that I can quickly apply for this part. Thank you. |
1.2.6 doesn't seem to work either:
when doing axiosInstance.interceptors.request.use(
AxiosLogger.requestLogger,
AxiosLogger.errorLogger,
); |
Thanks @hg-pyun 🙏 I have tested this with:
I still get the same build error. Steps to reproduce:
|
@hg-pyun Can this issue be closed? I tested this on 2.7.1 and I now have no type issues! |
@gvanderclay Still same problem with 2.7.1. Pushed a new branch |
@simenflatby, I've tested with axios 1.6.7 and axios-logger 2.7.1 and am no longer encountering the issue. If there's a specific need to ensure compatibility with axios version 1.3.0, the problem seems to have been resolved. |
@gvanderclay Thanks for coming back to me. I observe the same problem for 1.6.7. It might ofc. be something wrong with the minimal example I'm testing with, but I do not have the time at the moment to investigate. If you want to have a look, I have pushed a new branch
|
@simenflatby Upon revisiting your code, I realized the problem arises when the import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import { requestLogger, responseLogger } from 'axios-logger';
const axiosRequestConfig: AxiosRequestConfig = {};
const axiosInstance: AxiosInstance = axios.create(axiosRequestConfig);
axiosInstance.interceptors.request.use(requestLogger);
axiosInstance.interceptors.response.use(responseLogger); This should fix the type mismatch error. I apologize for not catching this detail in your initial code example. Please give this a try and let me know if it resolves the issue on your end. |
@simenflatby, I also want to add that if the use of a wrapper function for the import axios, {
AxiosInstance,
InternalAxiosRequestConfig,
} from 'axios';
import { requestLogger } from 'axios-logger';
const axiosRequestConfig: InternalAxiosRequestConfig = {};
const axiosInstance: AxiosInstance = axios.create(axiosRequestConfig);
const axiosRequestLogger = (
config: InternalAxiosRequestConfig
): InternalAxiosRequestConfig => requestLogger(config);
axiosInstance.interceptors.request.use(axiosRequestLogger); Notice that |
@gvanderclay Nice! I remember trying this approach when I first reported the issue, but it did not work then. Forgot about that earlier Today, but I have tested it now and it works. It was fixed as of Closing. Fixed by #147. |
@simenflatby Glad I could help! |
Is your feature request related to a problem? Please describe.
As of axios 1.3.0, there is a breaking change in the use of request interceptors (introduced in axios/axios#5486) that is not compatible with the exported
requestLogger
of this lib.Versions
Describe the solution you'd like
Add support for the breaking change so that axios >= 1.3.0 can be used with this lib.
Additional context
To reproduce:
npm i
npm run build
The text was updated successfully, but these errors were encountered: