@@ -211,12 +211,10 @@ export class KoaDriver extends BaseDriver implements Driver {
211211 }
212212
213213 // set http status code
214- if ( action . undefinedResultCode && result === undefined ) {
215- if ( action . undefinedResultCode instanceof Function ) {
216- throw new ( action . undefinedResultCode as any ) ( options ) ;
217- }
214+ if ( result === undefined && action . undefinedResultCode && action . undefinedResultCode instanceof Function ) {
215+ throw new ( action . undefinedResultCode as any ) ( options ) ;
218216 }
219- else if ( action . nullResultCode && result === null ) {
217+ else if ( result === null && action . nullResultCode ) {
220218 if ( action . nullResultCode instanceof Function ) {
221219 throw new ( action . nullResultCode as any ) ( options ) ;
222220 }
@@ -240,16 +238,16 @@ export class KoaDriver extends BaseDriver implements Driver {
240238
241239 return options . next ( ) ;
242240
243- } else if ( action . renderedTemplate ) { // if template is set then render it // todo : not working in koa
241+ } else if ( action . renderedTemplate ) { // if template is set then render it // TODO : not working in koa
244242 const renderOptions = result && result instanceof Object ? result : { } ;
245243
246244 this . koa . use ( async function ( ctx : any , next : any ) {
247245 await ctx . render ( action . renderedTemplate , renderOptions ) ;
248246 } ) ;
249247
250248 return options . next ( ) ;
251-
252- } else if ( result != null ) { // send regular result
249+ }
250+ else if ( result != null ) { // send regular result
253251 if ( result instanceof Object ) {
254252 options . response . body = result ;
255253 } else {
@@ -258,7 +256,14 @@ export class KoaDriver extends BaseDriver implements Driver {
258256
259257 return options . next ( ) ;
260258 }
261- else { // send null/undefined response
259+ else if ( result === undefined ) { // throw NotFoundError on undefined response
260+ const notFoundError = new NotFoundError ( ) ;
261+ if ( action . undefinedResultCode ) {
262+ notFoundError . httpCode = action . undefinedResultCode as number ;
263+ }
264+ throw notFoundError ;
265+ }
266+ else { // send null response
262267 if ( action . isJsonTyped ) {
263268 options . response . body = null ;
264269 } else {
@@ -267,18 +272,10 @@ export class KoaDriver extends BaseDriver implements Driver {
267272
268273 // Setting `null` as a `response.body` means to koa that there is no content to return
269274 // so we must reset the status codes here.
270- if ( result === null ) {
271- if ( action . nullResultCode ) {
272- options . response . status = action . nullResultCode ;
273- } else {
274- options . response . status = 204 ;
275- }
276- } else if ( result === undefined ) {
277- const notFoundError = new NotFoundError ( ) ;
278- if ( action . undefinedResultCode ) {
279- notFoundError . httpCode = action . undefinedResultCode as number ;
280- }
281- throw notFoundError ;
275+ if ( action . nullResultCode ) {
276+ options . response . status = action . nullResultCode ;
277+ } else {
278+ options . response . status = 204 ;
282279 }
283280
284281 return options . next ( ) ;
0 commit comments