Skip to content
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

Add optional chaining to ensure compatibility with mocking library #682

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

QuentinLemCode
Copy link

Solve #675

@TiddoLangerak
Copy link

I'm not quite sure if this is desirable, as this changes the contract (thus is a breaking change). I wouldn't expect the values to be undefined in tests (or anywhere else for that matter). I think the minimal change needed to make this work with nock is to replace port: axiosError.request.agent.defaultPort, with port: axiosError.request.socket.localPort - without optional chaining. This preserves the contract, and thus is a non-breaking change that addresses the issue.

@QuentinLemCode
Copy link
Author

QuentinLemCode commented Apr 15, 2024

I'm not quite sure if this is desirable, as this changes the contract (thus is a breaking change). I wouldn't expect the values to be undefined in tests (or anywhere else for that matter). I think the minimal change needed to make this work with nock is to replace port: axiosError.request.agent.defaultPort, with port: axiosError.request.socket.localPort - without optional chaining. This preserves the contract, and thus is a non-breaking change that addresses the issue.

You are right, my change made the type invalid (in fact, it was already), but I'd rather update the contract.
I'm not sure the object socket is always present. Do you have documentation about that?

@TiddoLangerak
Copy link

https://nodejs.org/api/http.html#requestsocket

@QuentinLemCode
Copy link
Author

QuentinLemCode commented Apr 15, 2024

@TiddoLangerak
Thanks, but I'm still unsure that this object is always present
There can be cases where the request has not been done yet : request cancellation, request interceptor failed, payload transform error ...

The request object is marked as optional in the Axios type definition. We should reflect this in the ApiError type definition.

Still, I have updated the code to use axiosError.request.socket.localPort first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants