【发布时间】:2016-01-08 09:14:09
【问题描述】:
我使用 node + express 作为后端,postgresql 用于数据库,EJS 用于前端。
我正在为服务器启动/停止/日志使用 pm2 包。
有时 API 查询错误意味着服务器在 1/2 分钟后没有响应,出现 504 网关超时错误。
示例:我正在访问此页面中的http://mysiteurl/index url 我有一些错误或异常意味着我尝试连接另一个页面http://mysiteurl/about,此页面也收到错误:504 网关超时
有时在 /index 调用中会出错
错误详情:
{ [error: invalid input syntax for integer: "undefined"]
name: 'error',
severity: 'ERROR',
code: '22P02',
detail: undefined,
hint: undefined,
position: '87',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'numutils.c',
line: '62',
routine: 'pg_atoi' }
例如这里我的 /index 和 /about 页面代码代码:
router.get('/index', function(req, res) {
globaldetails.video(userId, function(err, videoList) {
users.getUserDetails(userId, function(err, userDetails) {
globaldetails.expertContent(userId, function(err, expertContent) {
res.render('users/index', {
video : videoList.rows,
userDetails : userDetails.rows,
expertContent : expertContent.rows,
});
});
});
});
});
router.get('/about', function(req, res) {
res.render('users/about');
});
function video(userId, callback) {
client.query("select * from video where userId='" + userId + "' ", function(err, video) {
console.log(err);
callback(err, video);
});
}
function getUserDetails(userId, callback) {
var query = "select * from users where userId='" + userId + "' ";
console.log(query);
client.query(query, function(err, result) {
if (err) {
console.log(err);
} else {
callback(err, result);
}
});
}
function expertContent(userId, callback) {
var query = "select * from content where userId='" + userId + "' ";
client.query(query, function(err, expertContent) {
if (err) {
console.log(err);
} else {
callback(err, result);
}
});
}
任何人都可以为此提供帮助。
预期结果:当我收到错误 /index api 调用时,它不应该影响 /page api 调用。
【问题讨论】:
标签: node.js postgresql express