Recaptcha Handling Throwing Exception Inside Promise with catch - node.js

Does anybody know how to handle the error from below properly? Obviously, I am using a 3rd party library that performs an internal HTTP poll to a remote API, sometimes, it throws a connection refusal error and crashes the whole NodeJS process.
return new Promise((resolve, reject) => {
page.getRecaptchaSolutions(captchas).then(({ solutions, solErrors }) => {
if (solErrors)
reject(solErrors);
resolve(solutions)
})
.catch(error => {
reject(new Error(error))
})
})
Error: getaddrinfo EAI_AGAIN 2captcha.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on ClientRequest instance at:
at Socket.socketErrorListener (_http_client.js:406:9)
at Socket.emit (events.js:223:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:81:21) {
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: '2captcha.com'
}

Related

Node Server ECONNRESET error occurs after running a sql request

I'm making a node server using socket.js and a MYSQL DB,
socket.on("signUp", (userSignUp) => {
console.log(userSignUp);
con.connect(function() {
con.query("SELECT COUNT(*) AS count FROM users WHERE username = '" + userSignUp.username + "'", function (err, result, fields) {
console.log(result[0].count);
if (result[0].count >= 1) {
socket.emit("signUpError", 'user-allready-exists');
return;
}
});
});
});
When I run this function, it successfully gets the data from the db however after aproximatly 30 seconds, it gives me this error>>>
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (D:\Projects\server\node_modules\mysql\lib\Connection.js:423:8)
at Protocol.emit (node:events:513:28)
at Protocol._delegateError (D:\Projects\server\node_modules\mysql\lib\protocol\Protocol.js:398:10)
at Protocol.handleNetworkError (D:\Projects\server\node_modules\mysql\lib\protocol\Protocol.js:371:10)
at Connection._handleNetworkError (D:\Projects\server\node_modules\mysql\lib\Connection.js:418:18)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
I have had a good look around, but i can't seem to find what is causing this issue. Any help would be greatly appreciated.

ssl3_get_record:wrong version number, ERPROTO Error when trying to connect using a proxy from an online list

I am trying to connect to a kahoot using a proxy from an online proxy list. The proxy is up, and works just fine so that isn't the problem, but I can't actually connect to it with a request from the code. I've tried using http, https, socks4 and socks5 proxies, all of them return the same error. Is there something I'm missing or need to add? The "options" and "proxy" is just an http request same as what you would see on https://nodejs.org/api/http.html#http_http_request_options_callback
My code:
proxy: (options)=>{
return Object.assign(options,{
host: "51.104.203.226:33800",
});
The full error:
{
description: 'Request failed or timed out.',
error: RequestError: write EPROTO 14200000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
at ClientRequest.<anonymous> (C:\Users\queba\Desktop\kahootspam\node_modules\kahoot.js-latest\node_modules\got\dist\source\core\index.js:970:111)
at Object.onceWrapper (node:events:628:26)
at ClientRequest.emit (node:events:525:35)
at origin.emit (C:\Users\queba\Desktop\kahootspam\node_modules\kahoot.js-latest\node_modules\#szmarczak\http-timer\dist\source\index.js:43:20)
at TLSSocket.socketErrorListener (node:_http_client:494:9)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {
code: 'EPROTO',
timings: {
start: 1667511954639,
socket: 1667511954641,
lookup: 1667511954765,
connect: 1667511954765,
secureConnect: undefined,
upload: 1667511954893,
response: undefined,
end: undefined,
error: 1667511954894,
abort: undefined,
phases: [Object]
}
}
}

Node JS trying to download a number of images. Stream seems to keep being closed

I'm looping through quite a lot of images to download from a website using this function:
const fileGet = (url, path, callback) => {
request.head(url, (err, res, body) => {
request(url)
.pipe(fs.createWriteStream(path))
})
.on('error', function(err, res) {
console.log(err + res)
})
}
It seems to get so far and then the stream seems to be closed. I've been doing some googling and people mention it could be trying to resolve too many dns lookups in a given time.
This is the error I'm getting:
node:events:371
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND www.domain.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
Emitted 'error' event on Request instance at:
at Request.onerror (node:internal/streams/legacy:62:12)
at Request.emit (node:events:394:28)
at Request.onRequestError (C:\Scraper\node_modules\request\request.js:877:8)
at ClientRequest.emit (node:events:394:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:193:8)
at emitErrorCloseNT (node:internal/streams/destroy:158:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'www.domain.com'
}
I've tried hard coding the IP/Host name in my Hosts file, and tried putting a pause in the requests, same problem. I've also upgraded to the last version of Node (16.4.0)
Still the same.
There is a lot of debate about this issue online. Has it even been resolved?
Thanks.
If anybody is interested, it was a DNS lookup issue, and sorted it by using DNS Cache.
Just wrapper my whole download process with an initial look up, and the rest ran like a dream.

UnhandledPromiseRejectionWarning WebSocket in NodeJs although implemented on error

I'm having issues with a webSocket connection (nodejs, ws). Now and then i see the following error message at the console and i don't know where it comes from. Seems like there is a problem with the internet connection or DNS server at the moment the error is raised. The application should be able to handle broken internet connection. At the moment the error is raised, the whole application stops.
The Error at the console:
(node:14656) UnhandledPromiseRejectionWarning: Error: Query timed out
at DNS._ontimeoutCheck (C:\Users\XYZ\Documents\nodedev\Server-DEV\node_modules\dns-socket\index.js:123:18)
at Timeout.ontimeoutCheck (C:\Users\XYZ\Documents\nodedev\Server-DEV\node_modules\dns-socket\index.js:53:10)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
(node:14656) UnhandledPromiseRejectionWarning: Error: Query timed out
Error: getaddrinfo ENOTFOUND connect.server.cloud
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on ServerCloud instance at:
at ServerCloud.<anonymous> (C:\Users\XYZ\Documents\nodedev\Server-
DEV\plugins\inbound\ks\ks.js:353:18)
at WebSocket.emit (events.js:223:5)
at ClientRequest.<anonymous> (C:\Users\XYZ\Documents\nodedev\Server-
DEV\node_modules\ws\lib\websocket.js:554:15)
at ClientRequest.emit (events.js:223:5)
at TLSSocket.socketErrorListener (_http_client.js:406:9)
at TLSSocket.emit (events.js:223:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:81:21) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'connect.server.cloud'
i have implemented the .on('error', (err) => { method in my code:
this._ws.on('error', function (error) {
this.connected = false;
this.emit('error', error);
this.LogAtMain('WebSocket Error: ' + error.message);
console.log('Error message: ' + error.message);
});
How can i catch this error unlike implementing the on(error) hook?
Somewhere in your code, you forgot to handle a promise rejection. That is why you are getting that error.
You can handle UnhandledPromiseRejectionWarning like this:
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason.stack);
// application specific logging, throwing an error, or other logic here
});

Cant find origin of Unhandled 'error' event ETIMEDOUT

I am building an application that is communicating with a local server through http requests, I decided to do a "real" test and it keeps throwing errors, but I cant track where the error is coming from, the stacktrace doesnt tell me where it originates from (in my app).
When I start my app it works for 20-30 seconds, it manages to get/send data to that local webserver, but after 20-30 seconds I get the following error:
events.js:287
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 192.168.55.213:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Emitted 'error' event on ClientRequest instance at:
at Socket.socketErrorListener (_http_client.js:426:9)
at Socket.emit (events.js:310:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
address: '192.168.55.213',
port: 80
}
I have tried all my http requests in a try/catch block and log the errors to try and pinpoint where it originates from but nothing, the try/catches dont work, because the error is still being thrown, so it is not from within my http requests and I cant figure out the origin of the error. My requests look something like this:
async RequestFunction(requesturl) {
return new Promise((resolve, reject) => {
try {
http.get(requesturl, (resp) => {
let data = "";
resp.on('data', (chunk) => data += chunk)
resolve(data)
});
} catch (error) {
console.log(`${requesturl}+${error.code}`);
}
}
}
But the catch never gets triggered. I am guessing that mostly what I am asking for is how to track where the error is originating from?
I have also tried wrapping my Request function in every place where I am calling and awaiting it with a try/catch block, same thing.

Resources