javascript - Mongoose 异常的事件名称
问题描述
我正在使用 winston 记录我的错误,但我遇到了一个死点。我在互联网上搜索,但我什么也没找到。也许你们可以在这里帮助我。
我有一个错误,我喜欢使用例如 process.on("Eventname", (ex) => { blah blah blah}) 来捕捉它
下面是我的错误:
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at NativeConnection.Connection.openUri (/Volumes/Seagate/Project/Noosy/node_modules/mongoose/lib/connection.js:846:32)
From previous event:
at NativeConnection.Connection.openUri (/Volumes/Seagate/Project/Noosy/node_modules/mongoose/lib/connection.js:849:10)
at /Volumes/Seagate/Project/Noosy/node_modules/mongoose/lib/index.js:351:10
at /Volumes/Seagate/Project/Noosy/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
From previous event:
at promiseOrCallback (/Volumes/Seagate/Project/Noosy/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/Volumes/Seagate/Project/Noosy/node_modules/mongoose/lib/index.js:1149:10)
at Mongoose.connect (/Volumes/Seagate/Project/Noosy/node_modules/mongoose/lib/index.js:350:20)
at connectDB (/Volumes/Seagate/Project/Noosy/DB/connect.js:4:19)
at module.exports (/Volumes/Seagate/Project/Noosy/startup/db.js:12:9)
at Object.<anonymous> (/Volumes/Seagate/Project/Noosy/index.js:12:24)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47 {
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
'localhost:27017' => ServerDescription {
address: 'localhost:27017',
error: Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1132:16) {
name: 'MongoNetworkError'
},
roundTripTime: -1,
lastUpdateTime: 19232686,
lastWriteDate: null,
opTime: null,
type: 'Unknown',
topologyVersion: undefined,
minWireVersion: 0,
maxWireVersion: 0,
hosts: [],
passives: [],
arbiters: [],
tags: []
}
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
[nodemon] app crashed - waiting for file changes before starting...
这是我的日志文件:
const config = require("config");
require("express-async-errors");
const winston = require("winston");
require("winston-mongodb");
module.exports = function () {
winston.handleExceptions(
new winston.transports.File({ filename: "logs/uncaughtExceptions.log" })
);
process.on(**"Mongoose Event Name"**, (ex) => {
console.log("WE GOT AN UNCAUGHT EXCEPTION");
winston.error(ex.message, ex);
process.exit(1);
});
process.on("unhandledRejection", (ex) => {
throw ex;
});
winston.add(new winston.transports.File(), { filename: "logs/logfile.log" });
winston.add(new winston.transports.MongoDB(), {
db: config.get("mongoDB.connString"),
level: "info",
});
};
任何帮助都非常受欢迎
非常感谢您并继续编码!
解决方案
推荐阅读
- youtube-api - Youtube Player API:使用 access_token 播放私人视频
- sql - 选择连接结果作为同一行的列
- javascript - jQuery按数据属性排序
- javascript - 相当于 Angular/Typescript 中的 $('link').each?
- python - 使用 python-docx 创建一个文档并通过 django 作为附件发送
- ibm-cloud - 将 Cloud Foundry 流式日志重定向到日志提供程序,如 papertrail 或其他
- firebase - Firebase Analytics app_remove 一段时间后没有触发?
- ros - 为什么我在 Ubuntu 18.04 上有 ROS Lunar?
- youtube - 嵌入 Codenameone Youtube 视频
- haskell - haskell中的高阶函数解谜函数