Lately, I'm using domain model pattern, and my controllers methods often looks like (yii2 example, verify user in loyalty system with Ajax response).if (LoyaltyDomModel::loyaltyVerification($post_data)) {    if (LoyaltyDomModel::setVerify(Yii::$app->user->identity, $post_data)) {        return  ['body'=>'successfull','status' => true];    }    else {        return  ['body'=>'unable update user','status' => 'error'];    }}else {    return  ['body'=>'errorcardno','status' => 'error'];}If logic is more complex I have a lot of if statement with model methods which return bool values, for example (I'm trying to decouple models logic in atomic methods), and it looks like not healthy. Should I encapsulate logic of return errors in models? What is best practices?
Error handling in controller (MVC structure)
php
I advice you forego if checks completely and go for try-catch blocks, and have your verifiers throw exceptions on error. So, you do something like this:try {     LoyaltyDomModel::loyaltyVerification($post_data);     LoyaltyDomModel::setVerify(Yii::$app->user->identity, $post_data);     return  ['body'=>'successfull','status' => true];} catch (LoyaltyVerificationException $e) {     return ['body' => $e->getMessage(), 'status' => 'error']} catch (UserUpdateException $e) {     return ['body' => $e->getMessage(), 'fields' => $e->getFields(), /* you can pass custom info to exceptions, right? */, 'status' => 'error'];}Also, it's not a good idea to return bool in one case ('status' = true) and string in another ('status' = 'error');