Ajax action returning error 500 along with data

Hi. I’m using Kartik’s DepDrop (as I’ve used in the past) and I created an action to return data for a dropdown, but I’m getting a weird error: the server returns error 500, but returns also the content!

For example in the controller I’ve created this action:




    public function actionCerca()

    {

        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;        

        return ['output' => [], 'selected' => 0];

     }



if I call it from the browser I get Internal Server Error BUT also the JSON encoded array.

The controller is standard, I made no customization and no additional filter or behavior.

How can it be? Thanks

Error 500 is an internal server error.

The reason can be from server overload to access denied to some resources to a misconfiguration in an .htaccess file.

At first try to check if there is any hint in you webserver log.

Anyway since you say that you get the output, the error happen after the script execution, so no configuration error should be involved. Also the overload should be excluded for the same reason.

Try guessing it is a write permission problem on the runtime directory.

At the end of the execution yii write runtime information (log, debug etc etc) in that directory.

indeed I’ve been stupid in not checking web server’s error log! There’s an exception on User model, which is rather strange as I’ve set no authentication in my project. Apparently the debug toolbar still requires an user. Commenting out the debug toolbar in config/web.php fixed. Maybe this is an issue which should be filed to the project?

thanks for the suggestion.

[font=“Courier New”][Mon May 15 07:11:52.170375 2017] [:error] [pid 10203] [client ::1:60493] PHP Fatal error: Uncaught Error: Class ‘app\\models\\User’ not found in /project/vendor/yiisoft/yii2/web/User.php:657

Stack trace:

#0 /project/vendor/yiisoft/yii2/web/User.php(188): yii\\web\\User->renewAuthStatus()

#1 /project/vendor/yiisoft/yii2/base/Component.php(132): yii\\web\\User->getIdentity()

#2 /project/vendor/yiisoft/yii2-debug/panels/UserPanel.php(54): yii\\base\\Component->__get(‘identity’)

#3 /project/vendor/yiisoft/yii2-debug/LogTarget.php(54): yii\\debug\\panels\\UserPanel->save()

#4 /project/vendor/yiisoft/yii2-debug/LogTarget.php(118): yii\\debug\\LogTarget->export()

#5 /project/vendor/yiisoft/yii2/log/Dispatcher.php(188): yii\\debug\\LogTarget->collect(Array, true)

#6 /project/vendor/yiisoft/yii2/log/Logger.php(177): yii\\log\\Dispatcher->dispatch(Array, true)

#7 [internal function]: yii\\log\\Logger->flush(true)

#8 {main in /project/vendor/yiisoft/yii2/web/User.php on line 65[/font]