yii_debug and session

Hi , I have a problem with a proyect basic, with the advanced proyect I don´t have problems.

The problem is when the sesión expired and yii_debug is false ,don´t redirect:

defined('YII_DEBUG') or define('YII_DEBUG', FALSE);

 public function actions()


        if (Yii::$app->user->isGuest) 


            return $this->redirect(['/login/lostsession']);            


The response is a code 500 and the screen is white.

When I change yii_debug to true , this redirect perfect to lostsession.

If I delete redirect ,this do it correct,

 when yii_debug  is true this send error in the layout that not recognize user->identity... ok

when yii_debug is false go to login/error ok

'errorHandler' => [

            'errorAction' => 'login/error',


I need your help,what can I do for redirect ?