I'm using the connect-timeout module. When the timeout fires, it seems to dump the following error message to the console:
ServiceUnavailableError: Response timeout
at IncomingMessage.<anonymous> (/app/node_modules/connect-timeout/index.js:75:8)
at emitOne (events.js:96:13)
at IncomingMessage.emit (events.js:188:7)
at Timeout._onTimeout (/app/node_modules/connect-timeout/index.js:48:11)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
How do I suppress these log messages? I don't particularly want to see them, because the timeout firing is not really an indicator that there is a problem... it's just doing its job. And this is especially because I can add my own error handling middleware to express that can pick and choose what (if anything) to do with the error.
You need to catch this from express, the code should look like:
function errorHandler (err, req, res, next) {
console.log("Oops")
}
app.use(errorHandler)
For more info:
https://expressjs.com/en/guide/error-handling.html
Related
I'm deliberately triggering an error in a stored procedure under certain conditions which I want to catch in my Node.js API which uses the Tedious package.
Code Snippet from API:
let request = new Request(sql, (err)=>{
if (err) {
sqlerr = err;
console.log(typeof(err));
console.log("**RQ-ERROR**", err);
}
});
In the callback of the "Request" object above there is an "err" parameter. The "typeof()" returns "object"; however, when I dump it to the console it looks like this:
**RQ-ERROR** { RequestError: Duplicate entry for specified period
at RequestError (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\tedious\lib\errors.js:32:12)
at Parser.tokenStreamParser.on.token (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\tedious\lib\connection.js:723:34)
at emitOne (events.js:96:13)
at Parser.emit (events.js:188:7)
at Parser.parser.on.token (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\tedious\lib\token\token-stream-parser.js:27:14)
at emitOne (events.js:96:13)
at Parser.emit (events.js:188:7)
at addChunk (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\readable-stream\lib\_stream_readable.js:297:12)
at readableAddChunk (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\readable-stream\lib\_stream_readable.js:279:11)
at Parser.Readable.push (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\readable-stream\lib\_stream_readable.js:240:10)
message: 'Duplicate entry for specified period',
code: 'EREQUEST',
number: 50000,
state: 1,
class: 16,
serverName: 'PERSODG2LNN52\\SQLEXPRESS',
procName: 'CreateStatusReport',
lineNumber: 44 }
This almost looks like a JavaScript object but, as you can see, the "RequestError" data isn't quoted nor is there a comma after the text "240:10)" just before the "message" member. I'm not sure if this is a bug in TDS or if I'm just missing something but I cannot access any of the members as it is. I'd have to convert it to a string and parse it which is fine but isn't very elegant.
Suggestions?
as you can see, the "RequestError" data isn't quoted nor is there a comma after the text "240:10)"
These are artifacts of the console logging out the error message. You can try it out for yourself with something like the following:
$ node
> console.log(new Error('this is an error object!'));
Error: this is an error object!
at repl:1:13
at Script.runInThisContext (vm.js:119:20)
at REPLServer.defaultEval (repl.js:332:29)
at bound (domain.js:395:14)
at REPLServer.runBound [as eval] (domain.js:408:12)
at REPLServer.onLine (repl.js:639:10)
at REPLServer.emit (events.js:194:15)
at REPLServer.EventEmitter.emit (domain.js:441:20)
at REPLServer.Interface._onLine (readline.js:290:10)
at REPLServer.Interface._line (readline.js:638:8)
I'm not exactly sure what the desired outcome of this question is, but try inspecting the err.message property rather than using the typeof operator.
So I have a discord bot which works perfectly fine, but after some time (about 30 minutes) the bot crashes with this error message:
Error: Unhandled "error" event. ([object Object])
at Client.emit (events.js:186:19)
at WebSocketConnection.onError (C:\Users\Paul\Desktop\Hype-Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:374:17)
at WebSocket.onError (C:\Users\Paul\Desktop\Hype-Bot\node_modules\ws\lib\event-target.js:128:16)
at emitOne (events.js:116:13)
at WebSocket.emit (events.js:211:7)
at _receiver.cleanup (C:\Users\Paul\Desktop\Hype-Bot\node_modules\ws\lib\websocket.js:211:14)
at Receiver.cleanup (C:\Users\Paul\Desktop\Hype-Bot\node_modules\ws\lib\receiver.js:557:13)
at WebSocket.finalize (C:\Users\Paul\Desktop\Hype-Bot\node_modules\ws\lib\websocket.js:206:20)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Does someone know how to solve this?
I've been looking for someone who needs some help with this sort of thing, and lo and behold here you are. I too have run into this issue. You have a network error that happens when your bot sends something called a heartbeat to the servers to say to them: i am online. Then the server will send it back. If it is sent and there is not a message returned from the server then it will give you your error. All you have to do is go into the following path in your bot folder /node_modules/discord.js/src/client/websocket/WebSocketConnection.js
Then in that file go to a section that looks like this:
onError(error) {
if (error && error.message === 'uWs client connection error') {
this.reconnect();
return;
}
/**
* Emitted whenever the client's WebSocket encounters a connection error.
* #event Client#error
* #param {Error} error The encountered error
*/
this.client.emit(Constants.Events.ERROR, error);
}
and what I did is change it to this:
onError(error) {
if (error && error.message === 'uWs client connection error') {
this.reconnect();
return;
}
console.log("Attempting to reconnect!")
return this.reconnect()
/**
* Emitted whenever the client's WebSocket encounters a connection error.
* #event Client#error
* #param {Error} error The encountered error
*/
this.client.emit(Constants.Events.ERROR, error);
}
I hope this helps!
Wishing you luck,
Zaedus
I'm using the thingdom/node-neo4j module like this:
var neo = require('neo4j');
var db = new new.GraphDatabase(...);
but when I call the cypher method with some invalid script, instead of returning an error (allowing me to handle it), it blows up:
db.cypher('// invalid cypher script', (err, res) => {
if (err) console.log('ERROR: ' + err);
console.log(res);
})
what I get is a stack trace that looks like this:
/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:20
Error.captureStackTrace(this, this.constructor);
^
TypeError: Error.captureStackTrace is not a function
at ClientError.Error [as constructor] (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:20:13)
at new ClientError (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:81:48)
at Function.__dirname.Error.Error._fromObject (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:70:14)
at /Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/GraphDatabase.js:302:25
at Request._callback (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/GraphDatabase.js:92:20)
at Request.self.callback (/Users/ekkis/dev/test/inc/node_modules/request/request.js:187:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/Users/ekkis/dev/test/inc/node_modules/request/request.js:969:12)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
I'm using node v7.3.0 and posted an issue with the maintainer here: https://github.com/thingdom/node-neo4j/issues/214 but so far no solution. is anyone else running into this? any solutions?
Is someone know why this issue my appears and how to catch it? I do not remove any jobs manually, use only .removeOnComplete(true) I have some different job processor for the same job task with different parameters. May it cause the issue? How to be in this case?
queue.create('task', jobData)
.removeOnComplete(true)
.priority('normal')
.attempts(3)
.save()
queue.process('task', 5, function (job, ctx, done) {
// First task prcessor
});
queue.process('task', 5, function (job, ctx, done) {
// Second task prcessor
});
Error:
Error: job "425596" doesnt exist
at Command.callback (/home/carmod/www/avitoparser/bundle/programs/server/npm/node_modules/kue/lib/queue/job.js:178:17)
at normal_reply (/home/carmod/www/avitoparser/bundle/programs/server/npm/node_modules/redis/index.js:714:21)
at RedisClient.return_reply (/home/carmod/www/avitoparser/bundle/programs/server/npm/node_modules/redis/index.js:816:9)
at JavascriptRedisParser.Parser.returnReply (/home/carmod/www/avitoparser/bundle/programs/server/npm/node_modules/redis/index.js:188:18)
at JavascriptRedisParser.execute (/home/carmod/www/avitoparser/bundle/programs/server/npm/node_modules/redis-parser/lib/parser.js:415:12)
at Socket.<anonymous> (/home/carmod/www/avitoparser/bundle/programs/server/npm/node_modules/redis/index.js:267:27)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
I'm currently using bodyParser with Express to accept JSON requests. Whenever I pass in an incorrectly formed JSON object it returns a nasty error via the endpoint and logs it to the console as well. The following is the error:
SyntaxError: Unexpected string
at Object.parse (native)
at parse (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17)
at /Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/read.js:108:18
at done (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14)
at IncomingMessage.onEnd (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
SyntaxError: Unexpected string
at Object.parse (native)
at parse (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17)
at /Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/read.js:108:18
at done (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14)
at IncomingMessage.onEnd (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
I'm wondering how I can suppress the error or patch this completely. I've investigated the error but can't find any specific recommendations for patching it.
It's common to declare an error handler with Express:
app.use(function(err, req, res, next) {
...
return res.sendStatus(500);
});
This will also catch errors thrown in middleware like body-parser.