Whether to generate an error for json request?

There is an action that accepts only ajax. Checks whether a record with the same id, and whether access to delete a record with that id. It works, but not sure about this part right here:
Yii::$app->response->setStatusCode('401',Yii::t('text','You are not allowed to perform this operation'));
 return false;

Here's the entire action:
public function actionDeleteComment($id)
{
 Yii::$app->response->format = Response::FORMAT_JSON;
 if($model = Comment::findOne($id)) {
 if (Yii::$app->user->can('updateComment', ['comment' => $model])) {
$model->delete();
 return ['status'=>'success','message'=>Yii::t('text','Your post deleted successfully')];
}else{
 Yii::$app->response->setStatusCode('401',Yii::t('text','You are not allowed to perform this operation'));
 return false;
}
}
 Yii::$app->response->setStatusCode('404',Yii::t('text','An error occurred'));
 return false;
 }

Is it worth doing setStatusCode or just return json, and there already in js if else parse error or not and display the error?
Error output from the script alertify.
All ideas, links and poking his nose in Kaku great respect.
July 8th 19 at 16:27
1 answer
July 8th 19 at 16:29
Solution
Return the HTTP status (this is what makes setStatusCode) - Yes, you have, it correctly, and to write js code easier. Your doubts is likely due to the fact that not everyone does - but this is purely because of the inexperience of those who does not.

Even if you have json, to the Board to read all about the rest of the documentation of yii (https://github.com/yiisoft/yii2/tree/master/docs/g... - there are many interesting things written in the framework, already something prepared for this.
thanks, rest I have. Normal draft with 1 ajax controller - Henderson_Beat commented on July 8th 19 at 16:32

Find more questions by tags PHPYiiJSONAJAX