by welefen

This commit is contained in:
welefen 2013-11-04 17:53:06 +08:00
parent ae7fcb5b67
commit 915df47617
4 changed files with 30 additions and 28 deletions

View File

@ -194,14 +194,19 @@ global.ucfirst = function(name){
* @param {[type]} obj [description]
* @return {[type]} [description]
*/
global.throw_error = function(obj){
global.throw_error = function(obj, http){
if (is_string(obj)) {
obj = {msg: obj};
};
obj = extend({
type: "error",
msg: ""
msg: "",
http: http
}, obj);
if (http) {
throw obj;
return;
};
throw new Error(JSON.stringify(obj));
}

View File

@ -23,8 +23,8 @@ module.exports = Behavior(function(){
throw_error({
type: "deny",
msg: "deny ip",
code: 403
})
code: 403,
}, this.http);
};
return true;
}

View File

@ -26,7 +26,7 @@ var App = module.exports = Class(function(){
if (!module) {
module = A(group + "Empty", this.http);
if (!module) {
throw_error(this.http.req.module + " module not found");
throw_error(this.http.req.module + " module not found", this.http);
};
};
var action = this.http.req.action;
@ -44,11 +44,11 @@ var App = module.exports = Class(function(){
return false;
})
if (flag) {
throw_error("action black");
throw_error("action black", this.http);
};
};
if (!/^[A-Za-z](\w)*$/.test(action)) {
throw_error('action name error');
throw_error('action name error', this.http);
};
if (typeof module[action] == 'function') {
if (C('url_params_bind')) {
@ -76,7 +76,7 @@ var App = module.exports = Class(function(){
return module[C('call_method')](action);
};
}
throw_error("action: "+action+" not found");
throw_error("action: "+action+" not found", this.http);
},
//加载自定义外部文件
loadExtFile: function(){

View File

@ -11,28 +11,25 @@ module.exports = {
},
register_exception: function(){
process.on('uncaughtException', function(err) {
if (err instanceof Error) {
var message = err.message;
try{
var obj = JSON.parse(message);
switch(obj.type){
case "deny":
__response.statusCode = obj.code || 403;
__response.write(obj.msg, C('encoding'));
break;
case "redirect":
__response.statusCode = obj.code || 302;
__response.setHeader("Location", obj.msg);
break;
case "error":
__response.write(err.stack, C('encoding'));
break;
}
}catch(e){
console.log(err.stack);
if (typeof err && err.http) {
var http = err.http;
switch(err.type){
case "deny":
http._res.statusCode = err.code || 403;
http._res.write(err.msg, C('encoding'));
break;
case "redirect":
http._res.statusCode = err.code || 302;
http._res.setHeader("Location", err.msg);
break;
default:
http._res.statusCode = err.code || 500;
http._res.write(err.msg, C('encoding'));
}
err.http._res.end();
return;
};
//__response.end();
console.log(err.stack);
});
},
buildApp: function(){