From e8eff9a094278d6f4dcf2010acd02748c19f605a Mon Sep 17 00:00:00 2001 From: welefen Date: Thu, 18 Sep 2014 20:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96action=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=97=B6=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Lib/Core/App.js | 12 +++++++++--- test/Lib/Core/App.js | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/Lib/Core/App.js b/lib/Lib/Core/App.js index 9855cf67..8e7dd345 100644 --- a/lib/Lib/Core/App.js +++ b/lib/Lib/Core/App.js @@ -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); } diff --git a/test/Lib/Core/App.js b/test/Lib/Core/App.js index 2885538f..cceb5535 100644 --- a/test/Lib/Core/App.js +++ b/test/Lib/Core/App.js @@ -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));