Authored by yyq

nginx 503 handel

... ... @@ -2,6 +2,15 @@ const _ = require('lodash');
const {YOLUCK_LIST_TYPE, YoLuckService} = require('../models/yoluck-service');
function _handelErrorMessage(e) {
if (e && e.statusCode === 503) {
e.title = '人数过多。。。';
e.message = '目前参与人数过多请点击刷新';
}
return e;
}
function index(req, res, next) {
let type = +req.query.type || YOLUCK_LIST_TYPE.running;
let uid = req.user.uid;
... ... @@ -17,7 +26,7 @@ function index(req, res, next) {
`/signin.html?refer=//m.yohobuy.com/activity/yoluck/index.html?type=${YOLUCK_LIST_TYPE.joined}`
);
} else {
return next(result.error);
return Promise.reject(result.error);
}
}
... ... @@ -30,8 +39,7 @@ function index(req, res, next) {
width750: true,
wechatShare: true
});
}).catch(next);
}).catch(e => next(_handelErrorMessage(e)));
}
function nextPage(req, res, next) {
... ... @@ -82,7 +90,7 @@ function detail(req, res, next) {
wechatShare: true
});
}).catch(next);
}).catch(e => next(_handelErrorMessage(e)));
}
... ...
... ... @@ -25,6 +25,33 @@ const forceNoCache = (res) => {
}
};
const _err503 = (req, res, code, err) => {
res.status(code);
if (req.xhr) {
return res.json({
code: err.code,
message: err.message || '服务器繁忙请稍后重试!'
});
}
return res.render('error/510', {
err: err,
module: 'common',
page: 'error',
title: err.title || '服务器繁忙 | Yoho!Buy有货 | 潮流购物逛不停',
pageHeader: headerModel.setNav({
navTitle: err.title || err.message || '服务器繁忙请稍后重试!'
}),
showRefresh: {
message: err.message,
btnName: '刷新重试'
},
pageFooter: true,
isErr: true
});
};
const _err510 = (req, res, code, err) => {
res.status(code);
... ... @@ -194,8 +221,10 @@ exports.serverError = () => {
return res.redirect(checkRefer.replace(replaceKey, req.protocol + '://' + req.get('host') + req.originalUrl));
} else if (err.code === 9999991 || err.code === 9999992 || +err.statusCode === 503) {
} else if (err.code === 9999991 || err.code === 9999992) {
return _err510(req, res, 510, err);
} else if (+err.statusCode === 503) {
return _err503(req, res, 510, err);
}
if (!res.headersSent) {
... ...
<div class="err-page yoho-page">
<div class="err-bg"></div>
<div class="err-bg {{#if showRefresh}}err-refresh{{/if}}">
{{#showRefresh}}
<div class="refresh-wrap">
<p class="refresh-msg">{{message}}</p>
<a class="refresh-btn" href="javascript:void(0)" onclick="location.reload()" >{{btnName}}</a>
</div>
{{/showRefresh}}
</div>
</div>
... ...
... ... @@ -10,4 +10,31 @@
background: url("img/common/404.png") no-repeat;
background-size: 100% 100%;
}
.err-refresh {
margin-top: -250px;
}
.refresh-wrap {
width: 460px;
position: absolute;
left: 50%;
top: 100%;
margin-left: -230px;
text-align: center;
.refresh-msg {
line-height: 1.4;
padding: 20px 0;
}
.refresh-btn {
width: 200px;
line-height: 60px;
background-color: #414141;
display: block;
color: #fff;
margin: 10px auto;
}
}
}
... ...