Resful WS Return

I have a restful ws as folliwing:





public function actionLogin($user, $password){

        $tech = Technical::findOne([

            'user' => $user,

            'password' => $password,

            'status' => 'A',

        ]);


        return $tech;

    }

When the technical exists everything is ok but when the technical doesn’t I receive this:


<?xml-stylesheet

href="chrome://global/locale/intl.css" type="text/css"

?>

<parsererror>

Error de lectura XML: no se encuentra el elemento Ubicación: http://localhost/project/api/web/v1/sites/login?user=cesar&password=hello Número de línea 1, columna 1:

<sourcetext> ^</sourcetext>

</parsererror>

Is this ok? I was expecting something like:

<response>

<name>Not Found</name>

<message>Object not found: 2</message>

<code>0</code>

<status>404</status>

<type>yii\web\NotFoundHttpException</type>

</response>

<response>

<name>Not Found</name>

<message>Object not found: 2</message>

<code>0</code>

<status>404</status>

<type>yii\web\NotFoundHttpException</type>

</response>

I hope you can help me. Thanks in advance :)

Should be like this:

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

if (!$tech)

throw new \yii\web\NotFoundHttpException;

Thanks! I have a question: This is the good way to do it? I mean, in this cases we need to validate it like this? I’m kind of new in yii and in general in web programming. Thanks for your help.