I am trying to get (StatusCode) in response of REST api while its just return field name and error message like this
[{"field":"Email","message":"Email \"[email protected]\" has already been taken."}]
I have added response
'response' => [
'class' => 'yii\web\Response',
'on beforeSend' => function ($event) {
$response = $event->sender;
if ($response->data !== null && Yii::$app->request->get('suppress_response_code')) {
$response->data = [
'success' => $response->isSuccessful,
'data' => $response->data,
];
$response->statusCode = 200;
}
},
],
suppress_response_codeis sent via$_GET?Yii::$app->request->get('suppress_response_code')and test it. If it fails then$response->datais null.