Axios error while calling an API from web service deployed on render

My express web server deployed on render throws an error on making a call to nominatim reverse api, which worked fine on local.

const response = await axios.get(
https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lon}
)

This is the error:
AxiosError [AggregateError]
at AxiosError.from (/opt/render/project/src/node_modules/axios/dist/node/axios.cjs:837:14)
at RedirectableRequest.handleRequestError (/opt/render/project/src/node_modules/axios/dist/node/axios.cjs:3016:25)
at RedirectableRequest.emit (node:events:530:35)
at eventHandlers. (/opt/render/project/src/node_modules/follow-redirects/index.js:14:24)
at ClientRequest.emit (node:events:518:28)
at TLSSocket.socketErrorListener (node:_http_client:500:9)
at TLSSocket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: ‘ETIMEDOUT’,
errors: [
Error: connect ETIMEDOUT 184.104.179.133:443
at createConnectionError (node:net:1646:14)
at Timeout.internalConnectMultipleTimeout (node:net:1705:38)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
errno: -110,
code: ‘ETIMEDOUT’,
syscall: ‘connect’,
address: ‘184.104.179.133’,
port: 443
},
Error: connect ENETUNREACH 2001:470:1:fa1::5:443 - Local (:::0)
at internalConnectMultiple (node:net:1180:16)
at Timeout.internalConnectMultipleTimeout (node:net:1710:5)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
errno: -101,
code: ‘ENETUNREACH’,
syscall: ‘connect’,
address: ‘2001:470:1:fa1::5’,
port: 443
}
],
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [ ‘xhr’, ‘http’ ],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 5000,
xsrfCookieName: ‘XSRF-TOKEN’,
xsrfHeaderName: ‘X-XSRF-TOKEN’,
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function], Blob: [class Blob] },
validateStatus: [Function: validateStatus],
headers: Object [AxiosHeaders] {
Accept: ‘application/json, text/plain, /’,
‘Content-Type’: undefined,
‘User-Agent’: ‘axios/1.5.1’,
‘Accept-Encoding’: ‘gzip, compress, deflate, br’
},
method: ‘get’,
url: ‘https://nominatim.openstreetmap.org/reverse?format=json&lat=30.385314913418373&lon=75.53667068481447’,
data: undefined
},

Hi there,

I’d suggest checking out this article for more information on ETIMEDOUT errors in Node
https://medium.com/@mr.pinai/understanding-http-keepalive-and-etimedout-errors-in-node-js-b987d075644f

Give that a try and let me know if it helps.

Regards,

Matt

1 Like

Thanks for the reply, tried configuring keepAlive, and timeouts, but to no avail.
Now I am considering moving the API call to frontend itself.

const axiosConfig = {
httpAgent: new http.Agent({
keepAlive: true,
timeout: 5000,
}),
httpsAgent: new https.Agent({
keepAlive: true,
timeout: 5000,
}),
timeout: 5000,
}

This is the config I tried. Moving the call to frontend has served my purpose for now. :+1: