I want to return data with the HTTP error code in Yii 1. So I used the following way to get the data:
$code = (0 == $ex->getCode()) ? (isset($ex->statusCode) ? $ex->statusCode : 500) : $ex->getCode();
$this->setOutputError($ex->getMessage());
$this->setOutputCode($code);
When I use it this way API returns data with 200 error code as below:
But I want to change header status 200, so I threw exception for this, then output data also changed. I want to change only the header status.
$code = (0 == $ex->getCode()) ? (isset($ex->statusCode) ? $ex->statusCode : 500) : $ex->getCode();
$this->setOutputError($ex->getMessage());
$this->setOutputCode($code);
throw new CHttpException(400, 'Bad Request');


returnstatement\Yii::$app->response->statusCode = XXXwhereXXXis a new status code. You have putCHttpExceptionin your code - are you sure you are using Yii 2 and not Yii 1?