Drupal 8 REST add custom error messages to existing core /entity/user/ resource I am using drupal 8 rest and I want to be able to do a few computations and return custom json messages as per the defined condition when posting a user. I am using the already existing /entity/user/ resource provided by core out of the box. I tried to create a custom module and tried to use the Drupal\rest\ResourceResponse class in the module file like below:

function magri_rest_user_presave($account) {

    if (isset($account-&gt;field_region-&gt;value)) {

        $taxonomy_query = \Drupal::entityQuery('taxonomy_term');
        $taxonomy_query -&gt;condition('vid', "region")
            -&gt;condition('name', $account-&gt;field_region-&gt;value);
        $tids = $taxonomy_query-&gt;execute();

        $tid = array_values($tids)[0];


        if($tid){
            //set taxonomy ref field on user entity
            $account-&gt;field_region_tax-&gt;target_id = $tid;

        }else{
            die;
            $response = ['message' =&gt; 'Region not found'];
            return new ResourceResponse($response);
        }
    }
}


This does not stop the rest call to return the custom message. Is there a way I can archive this withouts creating my own custom rest plugin?
You can't return a response from a presave hook. You can however throw an exception, which in a json route will return a json error message:

throw new NotFoundHttpException('Region not found!');


If you want to change the default error response, implement an exception subscriber to catch this exception and return your own response. 

For reference the default exception handler: ExceptionJsonSubscriber::on4xx