REST : how do you handle the rest_no_route error?

I dug in the codex and found some interesting functions.
This is how I finally did it :

function api_request($api_url = null, $params=null,$method = 'GET'){

    if (!$api_url){
        return new WP_Error('no_api_url',"Missing API URL");
    }

    //Create request
    $request = WP_REST_Request::from_url( $api_url );

    //Method
    $request->set_method( $method );

    //params
    switch($method){
        case 'GET':
            $request->set_query_params($params);
        break;
        case 'POST':
            $request->set_body_params($params);
        break;
    }

    //Get response
    $response = rest_do_request( $request );

    if ( $response->is_error() ) {
        return $response->as_error();
    }

    //Get datas
    $datas = $response->get_data();

    return $datas;

}