mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-25 14:42:47 +00:00
优化action不存在时的错误提示,并添加单元测试
This commit is contained in:
parent
de945032cd
commit
e8eff9a094
@ -145,10 +145,16 @@ App.getActionParams = function(fn, http){
|
||||
App.exec = function(http){
|
||||
'use strict';
|
||||
var controller = this.getBaseController(http, true) || this.getCallController(http, true);
|
||||
//controller不存在
|
||||
//controller或者action不存在
|
||||
if (!controller) {
|
||||
var cmessage = http.controller ? ' `' + http.controller + '`' : '';
|
||||
var err = new Error('Controller' + cmessage + ' not found. pathname is `' + http.pathname + '`');
|
||||
var path = getThinkRequirePath(ucfirst(http.group) + '/' + ucfirst(http.controller) + 'Controller');
|
||||
var cmessage;
|
||||
if (path) {
|
||||
cmessage = 'action `' + http.action + '` not found.';
|
||||
}else{
|
||||
cmessage = 'Controller' + (http.controller ? ' `' + http.controller + '`' : '') + ' not found.';
|
||||
}
|
||||
var err = new Error(cmessage + ' pathname is `' + http.pathname + '`');
|
||||
return getPromise(err, true);
|
||||
}
|
||||
|
||||
|
||||
@ -158,9 +158,10 @@ describe('App', function(){
|
||||
assert.deepEqual(data, ['', ''])
|
||||
})
|
||||
it('exec, controller not exist', function(done){
|
||||
var http = {group: 'home', controller: 'test', action: 'index', pathname: '/test'}
|
||||
var http = {group: 'home', controller: 'test111', action: 'index', pathname: '/test'}
|
||||
App.exec(http).catch(function(err){
|
||||
assert.equal(err.message, "Controller `test` not found. pathname is `/test`");
|
||||
console.log(err.message)
|
||||
assert.equal(err.message, "Controller `test111` not found. pathname is `/test`");
|
||||
done();
|
||||
})
|
||||
})
|
||||
@ -171,6 +172,16 @@ describe('App', function(){
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('exec, action not exist', function(){
|
||||
var filepath = path.normalize(LIB_PATH + '/Controller/Home/IndexController.js');
|
||||
mkdir(path.dirname(filepath));
|
||||
fs.writeFileSync(filepath, 'module.exports = Controller({__after: function(){return "__after"}})')
|
||||
var http = {group: 'Home', controller:'Index', action: 'test', pathname: '/test', post: {}, get: {}}
|
||||
App.exec(http).catch(function(err){
|
||||
assert.equal(err.message, "action not found. pathname is `/test`");
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('exec, controller exist', function(){
|
||||
var filepath = path.normalize(LIB_PATH + '/Controller/Home/IndexController.js');
|
||||
mkdir(path.dirname(filepath));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user