TypeError crashing application when using relative URL from axios
See original GitHub issueI got the following error coming from follow-redirects
:
/.../node_modules/follow-redirects/index.js:598
const dot = subdomain.length - domain.length - 1;
^
TypeError: Cannot read property 'length' of null
at isSubdomain (/.../node_modules/follow-redirects/index.js:598:41)
at RedirectableRequest._processResponse ((/.../node_modules/follow-redirects/index.js:432:7)
at ClientRequest.RedirectableRequest._onNativeResponse ((/.../node_modules/follow-redirects/index.js:57:10)
at Object.onceWrapper (events.js:520:26)
at ClientRequest.emit (events.js:400:28)
at ClientRequest.emit (domain.js:475:12)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:647:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:127:17)
at Socket.socketOnData (_http_client.js:515:22)
at Socket.emit (events.js:400:28)
and it happens when HTTP client (axios
) is trying to do GET request on relative URL: /console/external/content?url=https%3A%2F%2F...%2Faws.png
.
From my quick investigation it seems like currentHost
passed to isSubdomain
function is null
, but inside that function it is assumed that this parameter is a string.
Attachments:
This are dumps of some data in RedirectableRequest.prototype._processResponse
function:
this._options
- options.txtresponse
- response.txt
Environment:
node
- v14.18.1axios
- v0.26.1follow-redirects
- v1.15.1- nginx HTTPS webserver running on localhost
Not sure if it is on follow-redirects
or on axios
side, but that specific error is not handled and it crashes the app. Other errors like invalid URL when using absolute URLs are handled flawlessly.
Let me know if any additional data needed or if I should pass this issue to axios
guys.
Issue Analytics
- State:
- Created a year ago
- Comments:13
Top GitHub Comments
Thanks @qooban. v1.15.2 will now handle this gracefully by defaulting to localhost (6e2b86da90cde81f15a5ba1732a41fd1291f14d3), as Node does. However, I still recommend you use the full URL, as it seems to be a pure coincidence that it is indeed
localhost
in your case 🙂Yeah, you’re right. When using axios in browser relative URL should work, but in node.js environment (this is my case) it has no way to know how to transform it, so
baseURL
should be specified in axios config. When I set it ({ baseURL: 'https://localhost' }
), my migration script is not crashing anymore.Thanks for your patience and willingness to find the reason for the problem!