errorLoggerWithoutPromise cannot destructure url when using baseUrl in instance config
blowsie opened this issue · 8 comments
Describe the bug
It seems the destructuring does not work when using baseURL in config
To Reproduce
const API_URL = 'http://localhost:5000'
const api = axios.create({
baseURL: API_URL,
method: 'post'
})
if (process.env.NODE_ENV !== 'production') {
api.interceptors.request.use(
AxiosLogger.requestLogger,
AxiosLogger.errorLogger
)
api.interceptors.response.use(
AxiosLogger.responseLogger,
AxiosLogger.errorLogger
)
}
// Request
async function get(args){
const { data } = await api.post(`/validate/${args.code}`, {})
return data
}
get()
// Cannot destructure property `url` of 'undefined' or 'null'.
Expected behavior
error could be logged
Thank you for report. I will check this issue ASAP.
import axios from "axios";
import { requestLogger, responseLogger, errorLogger } from "axios-logger";
const API_URL = "https://y2iuo.csb.app/123";
const api = axios.create({
baseURL: API_URL,
method: "post"
});
api.interceptors.request.use(requestLogger, errorLogger);
api.interceptors.response.use(responseLogger, errorLogger);
// Request
async function get() {
const { data } = await api.post(`/123`, {});
return data;
}
get();
I test with above code. But works well. It maybe another issue.
Here are sandbox test code. https://codesandbox.io/s/axios-logger-issue-50-y2iuo
Please check your business logic. If there is no problem after checking, please contact me again. I would appreciate it if you could give us the code reproduced at jsfiddle
or sandbox.io
.
Thank you.
Hi @hg-pyun , firstly this lib great and i appreciate what you have done up until now, Thank you.
I have a similar issue where the entire url is not being shown in the console when using this lib.
We only get the api end point that is being used. I tried you codesandbox example as well and it was showing the same response for me.
what I expect to see is that when I use the above I want to see this in the log.
[API Call][Error] 01:05:48 https://y2iuo.csb.app/123 POST {}.
But instead what we see is this.
[Axios][Error] 01:05:48 /123 POST {}
I am getting a similar error.
Cannot read property 'url' of undefined
[Nest] 186837 - 2020-05-30 10:04:07 PM [ExceptionsHandler] Cannot read property 'url' of undefined +7094ms
TypeError: Cannot read property 'url' of undefined
at errorLoggerWithoutPromise (/home/codejamninja/Projects/appsaas-core/node_modules/.pnpm/registry.npmjs.org/axios-logger/2.3.1/node_modules/axios-logger/lib/logger/error.js:20:7)
at Object.errorLogger (/home/codejamninja/Projects/appsaas-core/node_modules/.pnpm/registry.npmjs.org/axios-logger/2.3.1/node_modules/axios-logger/lib/logger/error.js:42:25)
at /home/codejamninja/Projects/appsaas-core/dist/0.f29eba7e5230f77ce51a.hot-update.js:29:138
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async AuthService.authenticate (/home/codejamninja/Projects/appsaas-core/dist/0.dd97e155f6512bf42957.hot-update.js:66:29)
at async AuthController.postLogin (/home/codejamninja/Projects/appsaas-core/dist/0.a729b615aa20c66bea92.hot-update.js:38:32)
at async /home/codejamninja/Projects/appsaas-core/node_modules/.pnpm/registry.npmjs.org/@nestjs/core/7.1.1_59c22b4ffbdfb1e3406b39779023abf5/node_modules/@nestjs/core/router/router-execution-context.js:45:28
at async /home/codejamninja/Projects/appsaas-core/node_modules/.pnpm/registry.npmjs.org/@nestjs/core/7.1.1_59c22b4ffbdfb1e3406b39779023abf5/node_modules/@nestjs/core/router/router-proxy.js:8:17
at async /home/codejamninja/Projects/appsaas-core/node_modules/.pnpm/registry.npmjs.org/@nestjs/core/7.1.1_59c22b4ffbdfb1e3406b39779023abf5/node_modules/@nestjs/core/router/router-explorer.js:137:17
It looks like it is coming from this line.
https://github.com/hg-pyun/axios-logger/blob/master/src/logger/error.ts#L9
Ok, I just had to pass the config to the errorLogger. Weird, because the typescript definition for error logger does not have config.
@BobFactory
Thank you for the report. I've confirmed that it's reproduced. I will check the reason and give you a comment.
@codejamninja
We need to improve this so that we can clearly show errors. Thank you.